How to iterate through structure fields
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kelly Steele
am 10 Dez. 2014
Kommentiert: Star Strider
am 12 Dez. 2014
I have a bunch of reaction time data (scalar) from subjects and am trying to figure out how best to vectorize my code. I have N subjects, each has Y conditions, and the number of values are different between subjects and between conditions. Also the maximum number of entries is unknown. My script loops through each subject, loading their data and searching for particular conditions and saving it. And I don't know how maThus, I can't simply have a matrix that is NxY .
The first thing I thought of is to put them all in a structure A with the conditions as different fields:
A(1:n).condition1
A(1:n).condition2
etc
But there are two problems: 1) I can't iterate through the fields, which is efficient and what I want to achieve, and 2) I can't easily obtain the average reaction times per condition from each subject. I would like to call mean(A(:).condition1) and have it output a 1xN array of the averages but it doesn't work that way.
What is the best way to contain data of variable length such that I can loop through to perform functions on the data? Thank you!
0 Kommentare
Akzeptierte Antwort
Star Strider
am 10 Dez. 2014
I would use a Cell Array. They require a bit of experimenting to learn about with them and use them efficiently, but they would seem to be the best option for your data.
2 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!