Best method to create multi-dimensional data set?
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
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
Karim
2023년 1월 3일
whoops you were faster then me, sorry for the redundant answer
the cyclist
2023년 1월 3일
Not fully redundant! You added some info that I did not.
Joe Rustan
2023년 1월 4일
카테고리
도움말 센터 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!