Find the index of nonempty array in a structure for a particular field
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
naman
am 23 Jul. 2015
Kommentiert: Ali A. Ghafari
am 10 Jan. 2020
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 Kommentar
Cedric
am 23 Jul. 2015
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?
Akzeptierte Antwort
Andrei Bobrov
am 23 Jul. 2015
Bearbeitet: Andrei Bobrov
am 23 Jul. 2015
find(~cellfun(@isempty,{select.c}))
Weitere Antworten (1)
Jos (10584)
am 23 Jul. 2015
Bearbeitet: Jos (10584)
am 23 Jul. 2015
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)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!