Index Non-Empty Cells in Cell Array

396 次查看(过去 30 天)
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
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 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by