Search code examples
matlabcell-array

How to create cell arrays dynamically


I need to create 10 empty cells: Outlier1, Outlier2,...,Outlier10, each being a different size. Due to the use of a previously existing loop, I'd like to do something like this:

for z=1:10

sprintf('Outlier%d',z)=cell(size(R,2),1);

end

Basically, each cell will have a different size due to the fact that R changes with z. However, if I do this, I receive this error:

Subscripted assignment dimension mismatch.

Could anyone tell me how to get around this?


Solution

  • XX=cell(size(R,2),1); 
    
    eval(sprintf('Outlier%d=XX',z));