Save FOR loop values in a matrix or a vector
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
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?
0 件のコメント
回答 (1 件)
Image Analyst
2014 年 7 月 3 日
編集済み: Image Analyst
2014 年 7 月 3 日
0 投票
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 件のコメント
Image Analyst
2014 年 7 月 3 日
Regarding your edit, if you want an n^2 by 2 matrix, do this:
xy = [x_rot(:), y_rot(:)];
after your for loops conclude.
Agent Cooper
2014 年 7 月 3 日
Ben11
2014 年 7 月 3 日
Maybe something like that:
xy(x,y) = [x_rot(x,y),y(rot(x,y)];
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!