count number of elements in a cell

39 vues (au cours des 30 derniers jours)
Max
Max le 11 Nov 2015
Commenté : Star Strider le 11 Nov 2015
say I have x={'zyryan';'zythem';'zythia';'zythum';'zyzomys'}
how would I count the number of elements in x. There are 5 words in x so I would like the output to be 1
  1 commentaire
Stephen23
Stephen23 le 11 Nov 2015
Your example vector x has five elements (five cells), so where do you get the value 1 from?

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 11 Nov 2015
I have no idea what result you want, but the size function will work:
x={'zyryan';'zythem';'zythia';'zythum';'zyzomys'};
sz_x = size(x)
sz_x =
5 1
  2 commentaires
Max
Max le 11 Nov 2015
I would like the answer to just be 5
Star Strider
Star Strider le 11 Nov 2015
In that instance, the code becomes:
sz_x = length(x)
sz_x =
5

Connectez-vous pour commenter.

Plus de réponses (1)

Stephen23
Stephen23 le 11 Nov 2015
>> x={'zyryan';'zythem';'zythia';'zythum';'zyzomys'};
>> numel(x)
ans = 5

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by