Loop through array containing coordinates points
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Álvaro Recalde
el 8 de Feb. de 2022
Respondida: Arif Hoq
el 8 de Feb. de 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 comentarios
Respuesta aceptada
Arif Hoq
el 8 de Feb. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
