MATLAB: Delete a struct in a struct array

arraystruct

hi! I have the struct array a 1×3, I want to delete all the struct in the struct array in which the fields places and locs are zero. In this case a 1×1 as the fields places and locs equal to zero, so I want to delete it and transform a in a struct array from 1×3 to 1×2.
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?

Best Answer

>> idx = ~cellfun('isempty',{a.places});
>> b = a(idx)