Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Delete rows with NaN for a cell array

Asked by Rooy

Rooy (view profile)

on 26 Jun 2013
Accepted Answer by Tom

Tom (view profile)

I want to remove the rows that have NaN and still keep the dimension of the array intact.

 [              NaN]    [        NaN]    [       NaN]    [           NaN]
    [              NaN]    [        NaN]    [       NaN]    [           NaN]
    'Total RADIO Drops'    'Total Drops'    'CC DCR (%)'    'RADIO  DCR (%)'

Above is just an example, I have over a thousand rows.

The only problem I have now is removing rows which have NaN and string together

Thank you

1 Comment

Rooy

Rooy (view profile)

on 26 Jun 2013

Is there a way to delete the rows which have strings and Nan mixed together ?

    [              'A']    [        NaN]    [       NaN]    [           NaN]
    'Total RADIO Drops'    'Total Drops'    'CC DCR (%)'    'RADIO  DCR (%)'
Rooy

Rooy (view profile)

Products

No products are associated with this question.

2 Answers

Answer by Tom

Tom (view profile)

on 26 Jun 2013
Accepted answer
A(any(cellfun(@(x) any(isnan(x)),A),2),:) = [];

1 Comment

Rooy

Rooy (view profile)

on 26 Jun 2013

Thank you, it works

Tom

Tom (view profile)

Answer by Andrei Bobrov

Andrei Bobrov (view profile)

on 26 Jun 2013
Edited by Andrei Bobrov

Andrei Bobrov (view profile)

on 26 Jun 2013

A - your cell array

out = A(any(cellfun(@(x)any(~isnan(x)),A),2),:);

ADD

out = A(all(cellfun(@(x)any(~isnan(x)),A),2),:);

3 Comments

Rooy

Rooy (view profile)

on 26 Jun 2013

That works thank you, is there a way to delete the rows which have strings and Nan mixed together ?

Andrei Bobrov

Andrei Bobrov (view profile)

on 26 Jun 2013

see ADD part in my answer

Rooy

Rooy (view profile)

on 26 Jun 2013

Thank you for your great help

Andrei Bobrov

Andrei Bobrov (view profile)

Contact us