how to find out number of rows in particular matrix of the cell?

조회 수: 2 (최근 30일)
siddhesh rane
siddhesh rane 2013년 7월 15일
Suppose i have 1*2 cell as shown below
A B
[1 2] [1 2 ; 3 4]
how can i find out number of rows in each cell..in these example they are 1 and rsply. for A and B.

채택된 답변

Evan
Evan 2013년 7월 15일
편집: Evan 2013년 7월 15일
>> a = {[1 2] [1 2; 3 4]}'
>> cellfun('size',a,1)
ans =
1 2
For more:
help cellfun
  댓글 수: 2
siddhesh rane
siddhesh rane 2013년 7월 15일
can you please tell me how can i get number of rows for only one matrix in cell .. for example i want no. of rows of second matrix..then answe r should be single digit i.e. 2.
Thanks in advance.
Evan
Evan 2013년 7월 15일
For that case, you wouldn't need to use cellfun:
>>size(a{2},2)
ans =
2

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 15일
out=cellfun(@(x) size(x,1),a)
  댓글 수: 4
Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 15일
Sorry, my connection is very bad, I did not see your answer, I will remove mine
Evan
Evan 2013년 7월 15일
편집: Evan 2013년 7월 15일
No worries, I often have the same problem. I just made that comment in order to clarify the difference between our answers (and to give you guys a chance to correct me in case I was mistaken :P). It wouldn't hurt to leave it up in order to have an example of how to use anonymous function handles with cellfun, especially since the list of available string arguments is pretty short and you oftentimes have to resort to function handles. I just wanted to clarify that, when available, the string arguments were best.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by