simple question in matlab

1 回表示 (過去 30 日間)
Bahareh
Bahareh 2011 年 6 月 23 日
Hello all,
I have the following for loop: for n = 3:32 r(n) = rank(magic(n)); end r
Shouldn't this loop start from n=3 and the size of r be 1x30? but why size of r is 1x30 and it puts r(1)=r(2)=0? how can I make the loop start from 3 not 1?

採用された回答

Laura Proctor
Laura Proctor 2011 年 6 月 23 日
You need to start your index value in r with 1 or else it populates up to the index value specified with zeros.
r = zeros(1,30);
for n = 3:32
r(n-2) = rank(magic(n));
end
r

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by