Use a loop or arrayfun to determine which elements of the array are empty:
empty_elems = arrayfun(@(s) isempty(sx) & isempty(sy),AB)
returns: [0 1 0]
or
empty_elems = arrayfun(@(s) all(structfun(@isempty,s)), AB);
which checks if all fields are empty (use any instead of all to check if any element is empty and not all).
Then delete them using logical indexing :
AB(empty_elems) = [];
A complete solution to your problem in the comments:
% find array elements that have all fields empty: empty_elems = arrayfun(@(s) all(structfun(@isempty,s)), AB); % copy non-empty elements to a new array `C`: C = AB(~empty_elems); % find elements of C that have y field >3 gt3_elems = arrayfun(@(s) sy<3,C); % delete those form C: C(gt3_elems) = [];
follow this code step by step and analyze the intermediate variables to understand what is going on. This should be clear enough.
source share