EyesOfÖzil
EyesOfÖzil

Reputation: 309

search and delete cell elements in matlab

I have a cell array of doubles and string in which a particular column looks like this

abc = {[110;10];[20;110];[10];[220];[380];[15];[220];[110;15];[110;20];[110]};

I would like to delete all elements which are less than 110 and I tried this statement abc(cellfun(@(x) any(x<110),abc),1) = [];

I got an error A null assignment can have only one non-colon index. Could someone please explain and rectify this?

I expect the output to be like this

abc = {[110];[110];[];[220];[380];[];[220];[110];[110];[110]};

Thanks!

Upvotes: 2

Views: 130

Answers (1)

tim
tim

Reputation: 10186

abc = abc(~cellfun(@(x) any(x<110),abc),1)?

That will invert the logical indices and then select the corresponding entries.

EDIT: After your comment was provided, that should do it:

abc_out = cellfun(@(x) x(x>=110), abc, 'UniformOutput', false)

Upvotes: 2

Related Questions