Greetings: let's suppose I have a loop that will execute 20 times, and within that loop I'll obtain a vector of information whose length will increase, each iteration, from 2 to 20. Now suppose I have a matrix of dimension 20, and during each iteration, I'd like to store that vector to one row of the matrix. For n = 2, the vector is length 2, and when I assign it to the first row of the matrix, call it A, I might try something like A(1,:) = p. But, since the length of the first row is 2o, and length of p is 2, there's a mismatch. Any clever suggestions on how to get around this issue.
Thanks so much...
John Sevic
$\endgroup$ 71 Answer
$\begingroup$This can be accomplished as follows:
P = zeros(19,20); %Preallocate memory
for i = 2:20 p = someFunction(); P(1:i,i-1)=p;
endThis will store each vector p in a row of P.