How to draw line between specific points?

조회 수: 29 (최근 30일)
Vikas Saroha
Vikas Saroha 2019년 5월 15일
편집: madhan ravi 2019년 5월 15일
I have two matrices
A = [1000 1000;...
1003 2640;...
2323 2638;...
2661 1096;...
1000 1000;...
1003 2640];
B = [1003 2640;...
2323 2638;...
2661 1096;...
1000 1000;...
2323 2638;...
2661 1096];
I want to plot lines between points mentioned in A and B. I am plotting it by
data = [A, B];
hold on
for i=1:6
plot(data(i, 1:2), data(i, 3:4));
end
Lines are not connected in the figure which is attached herewith.
Please help.

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2019년 5월 15일
For the first time around your loop you plot:
plot(data(1, 1:2), data(1, 3:4)); % i.e.
plot(A(1,:),B(1,:))
that corresponds to using [1000 1000] from A as X-coordinates, and [1003 2640] as Y-coordinates of your line.
I don't think that's what you want. Have a think about what lines you want to plot (manually, perhaps for only 2-3 rows
of A and B) and how you need to loop over the rows to achieve that. Homework hint: you are allowed to use nested loops.
HTH

추가 답변 (2개)

Sayyed Ahmad
Sayyed Ahmad 2019년 5월 15일
I hope the following codes are what you want:
clear all
close all
clc
A = [ 1000 1000; 1003 2640; 2323 2638; 2661 1096; 1000 1000; 1003 2640]
B= [ 1003 2640; 2323 2638; 2661 1096; 1000 1000; 2323 2638; 2661 1096]
x=zeros(size(A,1)*2,1)
ref=find(mod(1:size(x,1),2))
x(ref)=A(1:size(A,1),1)
x(ref+1)=B(1:size(A,1),1)
y(ref)=B(1:size(A,1),2)
y(ref)=A(1:size(A,1),2)
y(ref+1)=B(1:size(A,1),2)
plot(x,y)

KSSV
KSSV 2019년 5월 15일
data = [A ; B] ;
plot(data(:,1),data(:,2))

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by