MATLAB: Are first two elements of the computed r vector are 0

MATLABmatrixvectors

Hi, I'm learning Matlab along with linear algebra and I ran the code below.
for n=3:10
r(n) = rank(magic(n));
end
And my r resulted in:
r = 0 0 3 3 5 5 7 3 9 7
Please why are the first two elements 0?

Best Answer

Your for loop runs from 3 to 10, so it fills in the 3rd through 10th elements.
The first two are automatically set to 0 when you fill in the 3rd, because MATLAB has to fill in something to make that initial 3-element vector when you specified only the 3rd element. The default is to fill in 0.