Nested loop creating two dimensional cell

3 ビュー (過去 30 日間)
Marisa Mulvey
Marisa Mulvey 2022 年 4 月 27 日
コメント済み: Geoff Hayes 2022 年 4 月 27 日
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!
Geoff Hayes
Geoff Hayes 2022 年 4 月 27 日
Glad I was able to help, Marisa!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops 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