Best method to create multi-dimensional data set?
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
the cyclist
el 3 de En. de 2023
Editada: the cyclist
el 3 de En. de 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 comentarios
Karim
el 3 de En. de 2023
whoops you were faster then me, sorry for the redundant answer
the cyclist
el 3 de En. de 2023
Not fully redundant! You added some info that I did not.
Joe Rustan
el 4 de En. de 2023
Categorías
Más información sobre Multidimensional Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!