Index Non-Empty Cells in Cell Array

387 visualizaciones (últimos 30 días)
John F
John F el 28 de Jun. de 2012
Comentada: Serge Kogan el 21 de Oct. de 2020
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

Respuesta aceptada

Honglei Chen
Honglei Chen el 28 de Jun. de 2012
Editada: Honglei Chen el 28 de Jun. de 2012
x = {1,[],[],[]};
find(~cellfun(@isempty,x))
  6 comentarios
Md. Mubarak Hossain
Md. Mubarak Hossain el 16 de Mayo de 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?
Serge Kogan
Serge Kogan el 21 de Oct. de 2020
Md. Mubarak Hossain, You can get it by transposing the cell array a :
a={1 [] [];2 [] 4;5 6 []};
find(~cellfun(@isempty,a'))

Iniciar sesión para comentar.

Más respuestas (1)

Attila
Attila el 16 de Mayo de 2017
Dear Mubarak,
This will work : find(~cellfun(@isempty,a'));

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by