Loop through array containing coordinates points
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Álvaro Recalde
am 8 Feb. 2022
Beantwortet: Arif Hoq
am 8 Feb. 2022
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 Kommentare
Akzeptierte Antwort
Arif Hoq
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
