how can we find the intersect points of these two plots?
6 views (last 30 days)
Show older comments
MOHD UWAIS
on 16 Feb 2023
for y=-3:1:5;
G=[];
B=[];
for a=1:1:50
z=10;
x=a+y;
G=[G x];
b=z+30;
B=[B b];
end
B;
G;
a=1:1:50;
plot(a,G,'-')
hold on
plot(a,B,'-')
end
1 Comment
Rik
on 16 Feb 2023
You have put the names of several people in the tags (which doesn't actually do anything), you didn't format or run your code (I just did that for you), and instead of 2 lines you have 10 lines.
So what actually is your question?
Accepted Answer
Oguz Kaan Hancioglu
on 16 Feb 2023
Since B is constant it is easy to find the intersect point of lines using find command. Editted code listed below.
for y=-3:1:5;
G=[];
B=[];
for a=1:1:50
z=10;
x=a+y;
G=[G x];
b=z+30;
B=[B b];
end
B;
G;
a=1:1:50;
plot(a,G,'-')
hold on
plot(a,B,'-')
% find index
x = find(G == B(1));
% print intersect points
fprintf('intersect points = %.2f at %d, index number = %d\n',G(x),a(x),x);
% print intersect points on the plot
plot(a(x),G(x),'ro');
end
Best,
0 Comments
More Answers (2)
Sulaymon Eshkabilov
on 16 Feb 2023
Here is how to compute the intersect points of the plotted set of data points:
clearvars
close all
y=-3:1:5;
a=1:50;
for ii=1:numel(y)
G=[];
B=[];
for jj=1:numel(a)
z=10;
x=a(jj)+y(ii);
G=[G x];
b=z+30;
B=[B b];
end
plot(a,G,'-')
hold on
plot(a,B,'--')
Intersect = find(abs(B-G)==0);
ai = a(Intersect);
Gi = G(Intersect);
plot(ai, Gi, 'ro', 'MarkerFaceColor','y')
end
0 Comments
Askic V
on 16 Feb 2023
I think this small code snippet can be useful to you in future if you have a bit more general case:
x = 0:0.1:5;
y_val = 4*x-2;
intersect_points = [];
m = 2;
n = [1 2 3 4 5];
for i = n
y = m*x+i;
plot(x, y);
hold on
xisx = interp1(y-y_val, x, 0);
yisx = m*xisx+i;
plot(xisx, yisx,'o')
intersect_points = [intersect_points; xisx, yisx];
end
plot(x, y_val);
grid on
intersect_points
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices 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!