Nested loop creating two dimensional cell
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Marisa Mulvey
am 27 Apr. 2022
Kommentiert: Geoff Hayes
am 27 Apr. 2022
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 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 27 Apr. 2022
@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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!