Following @Jonas and @Clement-J.'s proposals, here is how toy use cells and structs:
N = 10; % number of matrices
cell_mat = cell(1, N); % pre allocate (good practice)
for ii = 1 : 10
cell_mat{ii} = rand( ii ); % generate some matrix for "mat"
struct_mat.( sprintf( 'mat%d', ii ) ) = rand( ii );
end
Nice thing about the struct (with variable field names) is that you can save it
save( 'myMatFile.mat', 'struct_mat', '-struct');
and you'll have variables mat1,...,mat10 in the mat-file! Cool!
Some good coding practices:
Pre-allocate matrices and arrays in Matlab. Changing a variable size inside a loop really slows down Matlab.
Do not use i and j as loop variables (or as variables at all) since they are used as sqrt(-1) by Matlab.
Why having variables with variable names? You need to have an extremely good reason for doing this! Please describe what you are trying to achieve, and I'm sure you'll get better and more elegant solutions here...
cells.structorcell- your approach leads you to writing very bad code.