how can we find the intersect points of these two plots?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
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
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
Best,
댓글 수: 0
추가 답변 (2개)
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
댓글 수: 0
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!