Possible Duplicate:
How to concatenate a number to a variable name in MATLAB?
Hi everyone, as the title, i’d like to learn if anyone knows how, in Matlab, create ‘n’ matrices in a loop.
Like this:
for (i=1:n)
p_i = P(i, :);
q_i = Q(i, :);
A_i = [p_i, p_i', q_i];
end
Matlab, of course, rewrites n times on the matrix A_i, but i would like to have n matrices of ‘i’ index.
Thank you in advance, have a good day!!
You could concatenate everything into a 3D array:
If you genuinely want
ndistinct matrices, then you will need a cell array. Your code would become something like:Note that you should carefully consider which would suit your needs the best. The only real advantage of a cell array is that it allows each element to be a different data-type, or a different-sized array. A 3D array has several advantages over a cell array of 2D arrays (you can sum over it, reshape it, slice 3D sub-chunks out of it, etc. etc.).