MATLAB: Replacing matrix rows in a loop

MATLABmatrix

Hi,
I am trying to build a n*k matrix but each row are produced by a function which has a 1*k output. How can I build that? I tried to build a n*k matrix of zeros and replace rows in a loop but since the dimensions are not same, I can't replace rows!
Thanks

Best Answer

X = zeros(100,10); %preallocate
for ii = 1:size(X,1) %loop over 100 rows
X(ii,:) = rand(1,10); %insert 10 random numbers
end