Loop through array containing coordinates points
7 views (last 30 days)
Show older comments
Hi, im trying to loop through an array containing coordinates in order to plot them and automatize this process, I've tried doing the following:
p0 = [1, 1];
p1 = [2, 3];
p2 = [4, 3];
p3 = [3, 1];
cords = [p0, p1, p2, p3];
for index = 1:length(cords)
pX = cords(index) % don't know how to take first value (1) not working
pY = cords(index) % same here
disp(pX)
disp(pY)
plot(pX,pY,.....)
end
I can't get something like this to work, I always end up getting just the first point instead of both of them.
I've also tried setting the points like
p0 = [1 1] %with spaces
But I don't know how to make it work. If you could help me I'd be very grateful, thanks
0 Comments
Accepted Answer
Arif Hoq
on 8 Feb 2022
Try this...
p0 = [1, 1];
p1 = [2, 3];
p2 = [4, 3];
p3 = [3, 1];
cords = [p0, p1, p2, p3];
N=length(cords);
for i = 1:length(cords)
pX{i} = cords(i); % don't know how to take first value (1) not working
pY{i} = cords(i); % same here
end
pX_value=[pX{:}];
pY_value=[pY{:}];
disp(pX_value)
disp(pY_value)
plot(length(pX_value),pX_value,'*')
ylim([0 5])
0 Comments
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots 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!