How do I loop through nested structures and index each component in a larger matrix?
2 次查看(过去 30 天)
显示 更早的评论
I have data on several subjects that each performed several trials of an activity. I have read all the data into structs in the format subject(1).trial(1).something subject(1).trial(2).somethingelse etc.
Now I need to read each of the trials into a row a big matrix [A] to perform some calculations on each trial, as if the subject didn't matter. So I started with this:
for i = 2:numSubjects
for j = 1:numTrials
A(j,:) = cat(2,subject(i).trial(j).torque_integral, subject(i).trial(j).work_integral);
end
end
But this will only work for the first subject. When the subject (i) increments to 3, the trial (j) will be back at one. So the idea is the output A lines up like this:
subject trial A
1 1 1
1 2 2
1 3 3
2 1 4
2 2 5
2 3 6
Hopefully this is clear. Any thoughts?
0 个评论
回答(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!