count number of elements in a cell

조회 수: 40 (최근 30일)
Max
Max 2015년 11월 11일
댓글: Star Strider 2015년 11월 11일
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
Stephen23
Stephen23 2015년 11월 11일
Your example vector x has five elements (five cells), so where do you get the value 1 from?

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2015년 11월 11일
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
Max
Max 2015년 11월 11일
I would like the answer to just be 5
Star Strider
Star Strider 2015년 11월 11일
In that instance, the code becomes:
sz_x = length(x)
sz_x =
5

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by