Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Save FOR loop values in a matrix or a vector

2 Ansichten (letzte 30 Tage)
Agent Cooper
Agent Cooper am 3 Jul. 2014
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
I have the following function with two FOR loops:
function Y = rot_mat(X)
n = sqrt(numel(X))
for x = 1:n
for y = 1:n
x_rot = x+y-1
y_rot = n-x+y
end
end
I am trying to save all the n x n values [x_rot, y_rot] in a vector or a n x n matrix. Could anyone, please, give me a hint on how to do that?

Antworten (1)

Image Analyst
Image Analyst am 3 Jul. 2014
Bearbeitet: Image Analyst am 3 Jul. 2014
Use x_rot(x,y) and y(rot(x,y).
By the way, you need to assign Y or else your function cannot be called.
  3 Kommentare
Agent Cooper
Agent Cooper am 3 Jul. 2014
I'm sorry, but if I use the
xy = [x_rot(:), y_rot(:)];
after the FOR loops I get only one pair of [x_rot, y_rot] (only the 2 last values).
Ben11
Ben11 am 3 Jul. 2014
Maybe something like that:
xy(x,y) = [x_rot(x,y),y(rot(x,y)];

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by