Clear Filters
Clear Filters

how can we find the intersect points of these two plots?

9 views (last 30 days)
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
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?

Sign in to comment.

Accepted Answer

Oguz Kaan Hancioglu
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
intersect points = 40.00 at 43, index number = 43 intersect points = 40.00 at 42, index number = 42 intersect points = 40.00 at 41, index number = 41 intersect points = 40.00 at 40, index number = 40 intersect points = 40.00 at 39, index number = 39 intersect points = 40.00 at 38, index number = 38 intersect points = 40.00 at 37, index number = 37 intersect points = 40.00 at 36, index number = 36 intersect points = 40.00 at 35, index number = 35
Best,

More Answers (2)

Sulaymon Eshkabilov
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

Askic V
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
intersect_points = 5×2
1.5000 4.0000 2.0000 6.0000 2.5000 8.0000 3.0000 10.0000 3.5000 12.0000

Categories

Find more on 2-D and 3-D Plots 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!