How can I find and label the intersecting point of two plots?

4 views (last 30 days)
Hello, I need help finding and labeling the intersect point for a plot of data and a line.
Here is my code:
Vs = 10;
R = 125;
Vd = 0: 1/1000 : 1;
Id = (-1/R)*(Vd)+(Vs/R);
plot (Vd,Id)
hold on
vd = [.86 .847 .819 .770 .75 .729 .6852 .64 .6113];
id = [.0914 .06102 .04178 .01964 .01360 .00927 .00423 .00167 .0009389];
plot (vd,id)
hold off
The resulting plot looks like this:
I need to find the point where the two plots intersect and display it some how. Any help is appreciated, Thank you in advance!

Answers (1)

Walter Roberson
Walter Roberson on 16 Sep 2022
you can interp1 vd id querying at Vd. Take the difference between that and Id and find the place that is closest to 0.
You might need to reverse vd id for interp1 purposes so that vd is ascending
  2 Comments
Elijah Vance
Elijah Vance on 16 Sep 2022
Would you mind showing my what that would look like in my code? I'm unfimiliar with interp1.
Walter Roberson
Walter Roberson on 17 Sep 2022
Vs = 10;
R = 125;
Vd = 0: 1/1000 : 1;
Id = (-1/R)*(Vd)+(Vs/R);
plot (Vd,Id)
hold on
vd = [.86 .847 .819 .770 .75 .729 .6852 .64 .6113];
id = [.0914 .06102 .04178 .01964 .01360 .00927 .00423 .00167 .0009389];
plot (vd,id)
hold off
interpolated_id = interp1(vd, id, Vd);
[~, bestidx] = min(abs(Id - interpolated_id));
fprintf('predict a crossing at index #%d where Id is %g and interpolation of id is %g\n', bestidx, Id(bestidx), interpolated_id(bestidx));
predict a crossing at index #853 where Id is 0.073184 and interpolation of id is 0.0727046
Not complete equality; do you need higher precision ?

Sign in to comment.

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!