How to access data that are cells in cells?
7 次查看(过去 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!