I have a struct data field with many fields:
The first field is goes from s1, s2... s8, s9 and defines the stage of data collection.
The second field is the name of the subject (of which there are hundreds) and does not have a pattern.
The third field is a binary variable, defining when the responses of the subjects are synced. (rSync or mSync)
Is there an easy way to loop through all permutations of this data and save each loop as a descriptive variable? I have been doing this manually, but I would like to automate this process:
s7_bm5.rSync = finalData.s7.bm5.rSync
s7_bm5.mSync = finalData.s7.bm5.mSync
s8_bm5.rSync = finalData.s8.bm5.rSync
s8_bm5.mSync = finalData.s8.bm5.mSync
...
So I basically want to create variables based on struct file name and have a way to loop through all struct subfields.
Any help is appreciated.
2 Comments
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/473601-looping-through-different-fields-in-struct#comment_728684
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/473601-looping-through-different-fields-in-struct#comment_728684
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/473601-looping-through-different-fields-in-struct#comment_728691
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/473601-looping-through-different-fields-in-struct#comment_728691
Sign in to comment.