How can I find and label the intersecting point of two plots?
4 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
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
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));
Not complete equality; do you need higher precision ?
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!