how to reshape a matrix using for loop

so i have this matrix called A that is 4772 X 1 in size and i want to reshape it in a "dummy matrix" with dimensions Rows (214) by Columns (223) but in a specific way.
The first value i want to place it is int the bottom-left corner , (last row, first column) and then use a for loops to continue iterate along the columns, in the last row , Once the last column is reached, pivot up one row then this process repeats.
so far i have this but im not doing it correctly.. can anyone help me?!
if true
% code
end
A= rand(4772,1);
dummy= zeros(214,223);
[m,n]=size(dummy);
if true
% code
end
count = 1;
for i= n:-1:1
for j =1:1:m
dummy(m,n) = A(count);
count = count + 1;
end
end
dummy

回答 (1 件)

James Tursa
James Tursa 2018 年 4 月 5 日
編集済み: James Tursa 2018 年 4 月 5 日

0 投票

Try switching the m and n in your for-loop indexing, and use (i,j) for your indexed assignment instead of (m,n). E.g.,
for i= m:-1:1
for j =1:1:n
dummy(i,j) = A(count);
Btw, there is an easy way to do this without for-loops, but I assume you were instructed to use for-loops for this.

1 件のコメント

Tony Garcia
Tony Garcia 2018 年 4 月 6 日
oh that's right.. thank you.. i did i typo there.. but im not sure with this code still the right answer to my question?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2018 年 4 月 5 日

コメント済み:

2018 年 4 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by