Effacer les filtres
Effacer les filtres

How do I loop through nested structures and index each component in a larger matrix?

3 vues (au cours des 30 derniers jours)
Dustyn Roberts
Dustyn Roberts le 11 Mar 2013
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?

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by