How do I loop through nested structures and index each component in a larger matrix?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!