MATLAB: I need help preallocating array

arrarpreallocating array

I need help making this array preallocated.
p = 10;
newArray = [];
array = [];
for i = 1:p
a= variable1;
b = variable2;
c = variable3;
d = variable4;
e = variable5;
array = [a,b,c,d,e]
newArray= [newArray array];
end

Best Answer

Look at the function "zeros".
array = zeros(1,5);
newArray = zeros(1,5*p);
and, in the loop
newArray((1+(i-1)*5):(i*5))=array;
This way all you need is allocated before the loop.
I assume that the assignments of a through e come from function that have a different value for different i's.
If they are the same, it's just a tiling problem. You need "repmat".