How to assign a variable name to a cell in a for loop?

조회 수: 5(최근 30일)
Zhané Murrell-Smith
Zhané Murrell-Smith 2020년 2월 7일
답변: Bhaskar R 2020년 2월 7일
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!

채택된 답변

Bhaskar R
Bhaskar R 2020년 2월 7일
definedsubjects = num2cell(rand(4,2));
for ii = 1:size(definedsubjects, 2)
col = definedsubjects(:, ii);
end

추가 답변(0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by