How do I make a new matrix for each iteration of a for loop?
14 views (last 30 days)
Show older comments
I need to make a matrix for each name of an item. I have a dataset that I am loading in that has 8 unique names, but that number could change. I tried to do this:
for length(snames)
% create a new matrix for each name
mMode{i} = [];
end
This obviosly just creates a 1x8 cell. I would just preallocate 8 matrices, but the number of names can change depending on the data set. Does anyone have any advice? Sorry if the wording is confusing.
0 Comments
Answers (1)
Voss
on 6 Dec 2022
mMode = cell(1,numel(snames));
for ii = 1:numel(snames)
mMode{ii} = []; % put a matrix or whatever you want into mMode{ii} here
end
0 Comments
See Also
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!