Index Non-Empty Cells in Cell Array

조회 수: 132 (최근 30일)
John F
John F 2012년 6월 28일
댓글: Serge Kogan 2020년 10월 21일
Hi,
I have the following cell array
TEST = [1] [] [] [] []
I want to get the index position of the non-empty cell. I know I can do this using a loop, but is there any single command (like "find") that will do this?
Thank you!
JF

채택된 답변

Honglei Chen
Honglei Chen 2012년 6월 28일
편집: Honglei Chen 2012년 6월 28일
x = {1,[],[],[]};
find(~cellfun(@isempty,x))
  댓글 수: 6
Md. Mubarak Hossain
Md. Mubarak Hossain 2017년 5월 16일
a={1 [] [];2 [] 4;5 6 []} find(~cellfun(@isempty,a)) ans =
1
2
3
6
8
Here I'm getting answer in column wise. But How to get row wise answer.
That's means I wanna get
ans=1 4 6 7 8 .
How to get it?
Serge Kogan
Serge Kogan 2020년 10월 21일
Md. Mubarak Hossain, You can get it by transposing the cell array a :
a={1 [] [];2 [] 4;5 6 []};
find(~cellfun(@isempty,a'))

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

추가 답변 (1개)

Attila
Attila 2017년 5월 16일
Dear Mubarak,
This will work : find(~cellfun(@isempty,a'));

카테고리

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