For loop that moves through array of X, Y coordinates
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
HumbleCoder
el 14 de Feb. de 2023
Comentada: HumbleCoder
el 14 de Feb. de 2023
I am trying to write a program that moves a picture around a screen at designated X,Y coordinates. I have assigned the X and Y vector locations and paired them in an array,
X_vector = [3; -3; -9; -15; -21; -15; -9; -3; 3; 3; -3; -9; -15; -21; -21; -15; -9; -3; 3; 3; -3; -9; -15; -21; -15; -9; -3; 3;];
Y_vector = [15; 15; 15; 15; 9; 9; 9; 9; 9; 3; 3; 3; 3; 3; -3; -3; -3; -3; -3; -9; -9; -9; -9; -9; -15; -15; -15; -15;];
Paired_Vectors = [X_vector, Y_vector];
but am having trouble telling Matlab to loop through the paired X,Y coordinates to assign the location of the picture to new locations after a specified amount of time.
What type of for loop should I run? Would it be better to run a for loop for X_vector and Y_vector indepedently? How would I still maintain the paired relationships?
0 comentarios
Respuesta aceptada
Image Analyst
el 14 de Feb. de 2023
Since you already have the x and y separately I don't see why you need to create a new, single matrix out of them. Just use the existing ones you already have.
X_vector = [3; -3; -9; -15; -21; -15; -9; -3; 3; 3; -3; -9; -15; -21; -21; -15; -9; -3; 3; 3; -3; -9; -15; -21; -15; -9; -3; 3;];
Y_vector = [15; 15; 15; 15; 9; 9; 9; 9; 9; 3; 3; 3; 3; 3; -3; -3; -3; -3; -3; -9; -9; -9; -9; -9; -15; -15; -15; -15;];
for k = 1 : numel(X_vector)
x = X_vector(k);
y = Y_vector(k);
% Now use x and y in some way.
end
The relationship is still "paired" because for any given index, the x value and y value correspond to each other.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!