How to assign a variable name to a cell in a for loop?
5 views (last 30 days)
Show older comments
I currently have a function that iterates through a data set and removes certain values into an excel file. I want to put all my data in at once (multiple individual tests) and separate out each test data.
I have a cell array named definedsubjects which I want to add into a for loop to take out individual columns, like this:
for i = definedsubjects
cols = i{:, a};
I want to use the cols variable to individually extract columns. However, when I use a 4x2 array for definedsubjects, i becomes a 4x1 array, only accessing the first column of data.
Any advice on how to fix this would be appreciated!
0 Comments
Accepted Answer
Bhaskar R
on 7 Feb 2020
definedsubjects = num2cell(rand(4,2));
for ii = 1:size(definedsubjects, 2)
col = definedsubjects(:, ii);
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Cell 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!