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.

采纳的回答

Geoff Hayes
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 个评论
Marisa Mulvey
Marisa Mulvey 2022-4-27
Hi Geoff,
My error that I receive for the loop is:
Error using load
Must be a text scalar.
I think I figured it out. I think it's because YA001 and YA002 only have 7 conditions instead of 9, so the final 2 conditions for those participants in the triallist is [] [] instead of a file. You're right that it's not a loop issue. Thank you so much for your help!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by