# Check if cell contains another cell

8 vues (au cours des 30 derniers jours)
Marc Laub le 20 Oct 2022
Commenté : Jiri Hajek le 21 Oct 2022
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 commentairesAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

the cyclist le 20 Oct 2022
a{1}='1-v1';
a{2}='.*';
a{3}='3+v2';
a{4}={'this is a cell'};
cellfun(@iscell,a)
ans = 1×4 logical array
0 0 0 1
##### 5 commentairesAfficher 4 commentaires plus anciensMasquer 4 commentaires plus anciens
Marc Laub le 20 Oct 2022
Yeah, guess the variable editor shows directly the string within the cell when its a 1x1 cell...

Connectez-vous pour commenter.

### Plus de réponses (1)

Jiri Hajek le 20 Oct 2022
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 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Jiri Hajek le 21 Oct 2022
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...

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

R2020a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by