MATLAB: Result producing 1×5 array instead of 10×5

cellcell arraycell arrayscellsnumeric arraynumeric arrays

Hi all,
I have the following code which I'm expecting to produce a 10×5 array but it's only giving me a 1×5, and I'm not sure why?
n = 10;
result = zeros(n,5);
for k=1:n;
A0=1;P0=29;g=rand;p=rand;B=rand;
result = [A0,P0,g,p,B];
end;
Alternatively, if I write the code this way I get a 10×1 cellular array, each entry of which represents a 1×5 numeric array. This gives me the number of results I want, but not in the format I'm looking for (which, again, is ultimately a 10×5 array). Thanks in advance!
n = 10;
result = cell(n,1);
for k=1:n;
A0=1;P0=29;g=rand;p=rand;B=rand;
result{k} = {A0,P0,g,p,B};
end;

Best Answer

You need to specify the index:
n = 10;
result = zeros(n,5);
for k=1:n;
A0=1;P0=29;g=rand;p=rand;B=rand;
result(k,:) = [A0,P0,g,p,B];
end;