## Index Non-Empty Cells in Cell Array

Asked by John F

### John F (view profile)

on 28 Jun 2012
Latest activity Answered by Attila

### Attila (view profile)

on 16 May 2017
Accepted Answer by Honglei Chen

### Honglei Chen (view profile)

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 (view profile)

Answer by Honglei Chen

### Honglei Chen (view profile)

on 28 Jun 2012
Edited by Honglei Chen

### Honglei Chen (view profile)

on 28 Jun 2012

x = {1,[],[],[]};
find(~cellfun(@isempty,x))

Honglei Chen

### Honglei Chen (view profile)

on 28 Jun 2012
Never thought about that but it surely is good to know, thanks Jan.
Christos Oreinos

### Christos Oreinos (view profile)

on 6 Oct 2016
The change in performance is significant for very large cells:
>> x=cell(10000000, 1);
>> x(1980) = {1};
>> tic; find(~cellfun(@isempty, x)); toc
Elapsed time is 5.852150 seconds.
>>
>> tic; find(~cellfun('isempty', x)); toc
Elapsed time is 0.041747 seconds.
Md. Mubarak Hossain

### Md. Mubarak Hossain (view profile)

on 16 May 2017
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?