% To save a scalar in a loop to vector
n = 10 ;
A = zeros(n,1) ;
for i = 1:n
A(i) = rand ;
end
% To save a vector in loop to a 2D matrix
n = 10 ; m = 5 ;
A = zeros(m,n) ;
for i = 1:m
A(i,:) = rand(1,n)
end
% To save a matrix in a loop to a 3D matrix
m = 10 ; n = 10 ; p = 5 ;
A = zeros(m,n,p) ;
for i = 1:p
A(:,:,i) = rand(m,n) ;
end