How to access data that are cells in cells?
조회 수: 12 (최근 30일)
이전 댓글 표시
Hello,
I have a variable that contains 931x1 cells and each cell contain 1x30 doubles. When I open the variable from workspace I see this: 1x1 cell 4x1 cell 4x1 cell and when I click on a cell I see 1x30 double How I can access these data? I tried with cat command but this create one cell array in which all cell are in one column and I want to a table 932x30. I tried also to access with {} but this take only the first cell and show it like [1x30 double]. How I could to acces all the cells?
Thank you very much for any help
댓글 수: 0
답변 (2개)
Guillaume
2015년 11월 23일
If you indeed have a 931x1 cell array and each cell contains a 1x30 vector, then
m = vertcat(c{:}) %where c is your cell array
will work. If it doesn't then you need to give us the output of
size(c)
class(c{1})
size(c{1})
댓글 수: 4
Guillaume
2015년 11월 23일
Sorry, made a typo, wrote a 1 instead of :. Now corrected.
Basically, because you've got cell arrays wrapped into a cell array you need to expand twice, c{:} each time.
Ideally, you'd correct the code that generated that cell array to remove the double wrapping.
Star Strider
2015년 11월 23일
Without seeing your data, it’s not possible to give a definitive Answer.
However, you can do multiple subscript reference addressing with cells, for example:
D = A{1}{1}
D = A{1}(1)
You will have to experiment with your own data. The cell2mat function is also an option for you to consider.
댓글 수: 4
Star Strider
2015년 11월 24일
None of your data that I looked at in your (931x1) cell are numeric. The contents are all strings, and they appear to be data on different major highways in some nation (I don’t recognise the designations).
This code for instance:
D = load('Kelly Kyriakou matlab.mat');
Cell = D.myData;
VarNames = Cell{1}(1:5)
S2 = Cell{2}(1:5)
S3 = Cell{3}(1:5)
produces this output:
VarNames =
'name'
'link_id'
'link_key'
'speed_sensor_id'
'count_sensor_id'
S2 =
'A2'
'1'
'1_AB'
''
''
S3 =
'A2'
'1'
'1_BA'
''
''
If you want to create a table with them you could do something like this:
T = table(S2,S3,'RowNames',VarNames)
T =
S2 S3
______ ______
name 'A2' 'A2'
link_id '1' '1'
link_key '1_AB' '1_BA'
speed_sensor_id '' ''
count_sensor_id '' ''
The data in the individual subcells (that I called ‘S1’ and ‘S2’ here) are mostly different lengths, so I have no idea how to suggest you deal with them. The table function requires that they all be the same length.
참고 항목
카테고리
Help Center 및 File Exchange에서 String Parsing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!