Nested loop creating two dimensional cell

조회 수: 6 (최근 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 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