フィルターのクリア

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

28 ビュー (過去 30 日間)
naman
naman 2015 年 7 月 23 日
コメント済み: Ali A. Ghafari 2020 年 1 月 10 日
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 Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by