필터 지우기
필터 지우기

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

조회 수: 28 (최근 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