필터 지우기
필터 지우기

delete a struct in a struct array

조회 수: 3 (최근 30일)
elisa ewin
elisa ewin 2016년 5월 13일
답변: Stephen23 2016년 5월 13일
hi! I have the struct array a 1x3, I want to delete all the struct in the struct array in which the fields places and locs are zero. In this case a 1x1 as the fields places and locs equal to zero, so I want to delete it and transform a in a struct array from 1x3 to 1x2.
I have used this code
for k=1:3
if and(isempty(s(k).places),isempty(s(k).locs))
s(k)=[]; a=s;
end
end
but it gives the error
'Index exceeds matrix dimensions.'
How can I do, to solve?

채택된 답변

Stephen23
Stephen23 2016년 5월 13일
>> idx = ~cellfun('isempty',{a.places});
>> b = a(idx)

추가 답변 (0개)

카테고리

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