필터 지우기
필터 지우기

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

조회 수: 9 (최근 30일)
MOHD UWAIS
MOHD UWAIS 2023년 2월 16일
답변: Askic V 2023년 2월 16일
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
Rik
Rik 2023년 2월 16일
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?

댓글을 달려면 로그인하십시오.

채택된 답변

Oguz Kaan Hancioglu
Oguz Kaan Hancioglu 2023년 2월 16일
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,

추가 답변 (2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 2월 16일
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 2023년 2월 16일
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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by