MATLAB: Simple question in matlab

general matlab usage

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 1×30? but why size of r is 1×30 and it puts r(1)=r(2)=0? how can I make the loop start from 3 not 1?

Best Answer

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