MATLAB: How to get rid of gaps in the structure

sortingstructures

Hi,
I have the following structure (see below) and I want to get rid of the gaps. How can I get rid of the empty places and align the structures with content underneath each other?
Structure:
[]
1×182 double
1×28 double
[]
1×3299 double
1×36 double
[]
1×173 double
[]
[]
1×34 double
1×32 double
1×64 double
[]

Best Answer

S = struct ;
for i = 1:2:10
S(i).val = rand(10,1) ;
end
% GEt the empty structures
idx = find(arrayfun(@(S) isempty(S.val),S));
% Remove empty structures
S(idx) = []
Related Question