Loop through array containing coordinates points

2 ビュー (過去 30 日間)
Álvaro Recalde
Álvaro Recalde 2022 年 2 月 8 日
回答済み: Arif Hoq 2022 年 2 月 8 日
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

採用された回答

Arif Hoq
Arif Hoq 2022 年 2 月 8 日
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)
1 1 2 3 4 3 3 1
disp(pY_value)
1 1 2 3 4 3 3 1
plot(length(pX_value),pX_value,'*')
ylim([0 5])

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by