Connect the dots with a loop
1 view (last 30 days)
Show older comments
arnaud ensberg
on 29 Apr 2015
Commented: arnaud ensberg
on 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
0 Comments
Accepted Answer
Image Analyst
on 29 Apr 2015
In the first plot(), inside the loop, you need to tell it to do lines, like plot(....., 'r*-')
3 Comments
Image Analyst
on 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
More Answers (0)
See Also
Categories
Find more on Point Cloud Processing 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!