# How to delete the columns in a structure array

11 views (last 30 days)
Tomer on 27 Feb 2020
Edited: Stephen Cobeldick on 27 Feb 2020
Hi.
I have a structure array HT (1 x 50000) with 20 fields. I want to delete the columns whose size is less than 10.

Stephen Cobeldick on 27 Feb 2020
"I have a structure array HT (1 x 50000) with 20 fields. I want to delete the columns whose size is less than 10."
Your structure only has one row, so it is not clear what "...size less than 10" refers to.
Tomer on 27 Feb 2020
All fields have same length, I want to delete that particular column whose field length is less than 10.

SS on 27 Feb 2020
Edited: SS on 27 Feb 2020
A similar question was asked by me in the past.
HT(any(cellfun(@numel,struct2cell(HT)) < 10)) = []

#### 1 Comment

Tomer on 27 Feb 2020
Thanks.

Stephen Cobeldick on 27 Feb 2020
Edited: Stephen Cobeldick on 27 Feb 2020
X = arrayfun(@(s)any(structfun(@numel,s)<10),S);
S(X) = []
Tested:
>> S = struct('A',{rand(1,99),rand(1,9),rand(1,99)}, 'B',{rand(1,99),rand(1,9),rand(1,99)})
S =
1x3 struct array with fields:
A
B
>> X = arrayfun(@(s)any(structfun(@numel,s)<10),S);
>> S(X) = []
S =
1x2 struct array with fields:
A
B