Best method to create multi-dimensional data set?
Afficher commentaires plus anciens
I have the following example data in Matlab.
Model-1: Set-1: [1 2 3]
Set-2: [5 6 7 8 9]
Set-3: []
Set-4: [21 22 23 24 25 26]
Model-2: Set-1: [2.5 43 22 28 71 101]
Set-2: [4 18 12]
Model-3: Set-1:...
.... and so on.
My goal is to iterate over all Models, then loop over the sets in each model and then read the contents of each set. The sets and contents for each model can different, e.g., Model-1 has 4 sets, Model-2 has only 2 sets, etc.
What would the best way to initialize and populate this information in Matlab? I've tried several variations with multi-dimensional arrays but can't get it working. TIA for the guidance, I'm sure this is quite easy to accomplish.
Joe
Réponse acceptée
Plus de réponses (1)
the cyclist
le 3 Jan 2023
Modifié(e) : the cyclist
le 3 Jan 2023
Model = cell(3,1); % Three models
Model{1} = cell(4,1); % Model 1 has four sets
Model{2} = cell(2,1); % Model 2 has two sets
Model{3} = cell(7,1); % Model 2 has seven sets
Model{1}{1} = [1 2 3]; % Contents of Model 1 Set 1
Model{1}{2} = [5 6 7 8 9]; % Contents of Model 1 Set 2
Model{2}{1} = [2.5 43 22 28 71 101]; % Contents of Model 1 Set 1
Note that the use of parentheses versus curly braces can be a bit tricky to under at the beginning. Use parentheses for the cell, and curly for the contents of the cell. See the difference here (and note that some cells have empty arrays, because I have not filled them yet.)
Model(1)
Model{1}
Model{1}(1)
Model{1}{1}
3 commentaires
Karim
le 3 Jan 2023
whoops you were faster then me, sorry for the redundant answer
the cyclist
le 3 Jan 2023
Not fully redundant! You added some info that I did not.
Joe Rustan
le 4 Jan 2023
Catégories
En savoir plus sur Multidimensional Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!