Nested loop creating two dimensional cell
6 次查看(过去 30 天)
显示 更早的评论
Hello,
I am writing a processing script, and I'm still pretty novice at MATLAB so any help would be appreciated. I have 10 participants in my data, and each participant has 9 trials of conditions. I want to use a loop to make a 10x9 cell where each cell is a 1x1 structure. With my current nested loop, the output IS a 10x9 cell where each cell is a 1x1 structure, BUT each cell in the first column of the only gives the first condition repeated over and over again for the first participant, and each cell in the second column only gives the first condition repeated over and over again of the second participant, etc. (as opposed to each column being a different condition and each row being a different participant). Does anyone know how I can fix it? The code is as follows:
lCond = length(triallist);
wCond = width(triallist);
for i=1:lCond
for j = 1:wCond
filename = triallist{j};
calcdata{i,j} = calc_splitbelt(filename,slowleg);
end
end
triallist is all of my data files, organized with conditions each being separated with a comma to create new columns and participants being separated with a semicolon to create new rows.
0 个评论
采纳的回答
Geoff Hayes
2022-4-27
@Marisa Mulvey - looking closely at your inner loop
for j = 1:wCond
filename = triallist{j};
calcdata{i,j} = calc_splitbelt(filename,slowleg);
end
while the filename changes on each iteration of the loop BUT there is no dependence on i. So if we consider each row in the first column where j equals 1 then
% for i == 1, j == 1
filename = triallist{1};
calcdata{1,1} = calc_splitbelt(filename,slowleg);
% for i == 2, j == 1
filename = triallist{1};
calcdata{2,1} = calc_splitbelt(filename,slowleg);
% for i == 3, j == 1
filename = triallist{1};
calcdata{3,1} = calc_splitbelt(filename,slowleg);
% etc.
then we see that each row in the first column is calculated the same way. This will be true for all columns. How should the participant i be used in this calculation? What is the format for the data in the triallist?
4 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!