Azzera filtri
Azzera filtri

Connect the dots with a loop

1 visualizzazione (ultimi 30 giorni)
arnaud ensberg
arnaud ensberg il 29 Apr 2015
Commentato: arnaud ensberg il 30 Apr 2015
Hi I have a point cloud :
point_cloud = [-1,0; 1,0; 1,2; -1,2; 0,3];
that I want connect according to two vectors :
k=[1 5 5 3 4]
l=[3 4 3 5 5]
it means : the first point is connected with the third, the fifth with the fourth
Here is my loop:
cc=point_cloud(:,1)
ll=point_cloud(:,2)
for m=1:size(k,1)
plot([point_cloud(k(m),1) point_cloud(l(m),1)],[point_cloud(k(m),2) point_cloud(l(m),2)])
hold on
end
plot(cc,ll,'r*')
hold off
but it draws only one segment
can you help me please

Risposta accettata

Image Analyst
Image Analyst il 29 Apr 2015
In the first plot(), inside the loop, you need to tell it to do lines, like plot(....., 'r*-')
  3 Commenti
Image Analyst
Image Analyst il 29 Apr 2015
Try this:
point_cloud = [-1,0; 1,0; 1,2; -1,2; 0,3]
k=[1 5 5 3 4]
l=[3 4 3 5 5]
x=point_cloud(:,1)
y=point_cloud(:,2)
for m = 1 : length(k)
index1 = k(m)
index2 = l(m)
plot([x(index1), x(index2)],[y(index1), y(index2)], 'r*-', 'LineWidth', 2)
hold on
end
grid on;
hold off
arnaud ensberg
arnaud ensberg il 30 Apr 2015
Thank you very much

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by