Find the index of nonempty array in a structure for a particular field

15 次查看(过去 30 天)
Hi I have a structure with one field e.g. select(i).c, where i=1,...,N. I want to find the index i for which select(i).c is nonempty. How can I do it ? Thanks
  1 个评论
Cedric
Cedric 2015-7-23
select is a struct array actually. Do you need the index of the non-empty content or would the content be enough? And what is the type/class of what is stored in field c?

请先登录,再进行评论。

采纳的回答

Andrei Bobrov
Andrei Bobrov 2015-7-23
编辑:Andrei Bobrov 2015-7-23
find(~cellfun(@isempty,{select.c}))

更多回答(1 个)

Jos (10584)
Jos (10584) 2015-7-23
编辑:Jos (10584) 2015-7-23
use ARRAYFUN
% create some data
for j=1:10, select(j).c = repmat(j,round(rand(1))) ; end
% engine
tf = arrayfun(@(k) ~isempty(select(k).c), 1:numel(select))
idx = find(tf)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by