MATLAB: How to delete field in struct in loop

structstructures

In have struct A having fields A1(2×1), A2(2×1), A3(12×1) ….A100(23×1). I want to delete fields whose size is (2×1). how to delete it

Best Answer

n1 = fieldnames(A);
Aout = rmfield(A,n1(cellfun(@numel,struct2cell(A)) == 2));