Dynamically Naming Structures
5 views (last 30 days)
Show older comments
I have a question that is proving very difficult to somebody with only two months of experience in Matlab. I want to create a series of nested structures, and need to have one level generate the variable dynamically. Here's my proposed structure:
pool.sub_X.trial_X.variables
pool: a structure containing all the data
sub_X: a structure for each of the subjects that were tested in an experiment. I would like X to be dynamically changed based on a numerical value it is given, resulting in a series of structures sub_1, sub_2, sub_3, etc. Total number of structures that will need to be created is unknown. (I was having trouble with this as it kept telling me I needed a cell array, and it wouldn't convert from a number to a cell.)
trial_X: similar to sub_X, based on the trial number it is given.
variables: this will several, predefined values that will be either numerical data or strings. I'm thinking the best way to do this would be to have a template structure that could easily be assigned to each trial.
I'm not sure if this all makes sense, but any pointers would be greatly appreciated. :)
0 Comments
Answers (1)
Walter Roberson
on 16 Mar 2012
Sure, see the dynamic field names part of this description:
0 Comments
See Also
Categories
Find more on Whos in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!