Check if cell contains another cell
4 次查看(过去 30 天)
显示 更早的评论
Hey,
I need to check if my cell contains another cell or if the contant is a character vector.
So I got a
a=1x130 cell
and
a{1}='1-v1';
a{2}='.*'
a{3}='3+v2'
a{4}=1x3 cell
...
So e need to check wether the cell content is a character vector like a{1} or a{3}, contains an operater such as a{2}, or a cell itsself with the same structure as a
Then I wanna
eval('(1-v1).*(3+v2)')
So with
ischar
I can check wether its .* or an character arry, but how do I check if its a subcell, to call the fiunction recursive?
Best regards
0 个评论
采纳的回答
the cyclist
2022-10-20
a{1}='1-v1';
a{2}='.*';
a{3}='3+v2';
a{4}={'this is a cell'};
cellfun(@iscell,a)
5 个评论
the cyclist
2022-10-20
编辑:the cyclist
2022-10-20
The image really isn't enough. I can't run the following code -- which exposes the fact the first cell really does contain another cell -- on your image.
load(websave("segs","https://www.mathworks.com/matlabcentral/answers/uploaded_files/1163423/testdata.mat"),"segs");
segs(1)
segs{1}
segs{1}{1}
segs(2)
segs{2}
I think you were getting fooled by the fact that the Variable Editor interface seems to look inside 1x1 cells.
更多回答(1 个)
Jiri Hajek
2022-10-20
Hi,
you can use the isa function:
isa(a{i},'cell')
Note that the use of eval is not recommended for many a good reason...
2 个评论
Jiri Hajek
2022-10-21
I believe you have got your answer already, as the cyclist pointed out the fact that variable viewer is not a reliable way to check the class of data, rather a viewer that helps you to analyze data. And we can trust the isa/iscell commands, which is not really surprising, considering how long they have been a part of MATLAB...
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!