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 strings for a cell array

Asked by Rooy

Rooy

on 26 Jun 2013
Accepted Answer by Andrei Bobrov

Andrei Bobrov

I have a cell array that contains a few rows of strings and want to delete the whole row if they are all strings.

 'Cause'                  'CSSR (%)'    'MO Attempts'    'MT Attempts'
              [1x20 char]    [       1]    [          1]    [          0]

I only want to delete the first row and not the second.

Thank you

0 Comments

Rooy

Rooy

Products

No products are associated with this question.

1 Answer

Answer by Andrei Bobrov

Andrei Bobrov

on 26 Jun 2013
Edited by Andrei Bobrov

Andrei Bobrov

on 26 Jun 2013
Accepted answer
A = {'Cause'                  'CSSR (%)'    'MO Attempts'    'MT Attempts'
      'fghytresdfhjjiiuyt'    [       1]    [          1]    [          0]};
out = A(any(~cellfun(@ischar,A),2),:);

or

out = A;
A(all(cellfun(@ischar,A),2),:) = [];

3 Comments

Rooy

Rooy

on 27 Jun 2013

This takes out the rows that have some strings and numbers, I need to take out the rows that only have strings in it.

Thank you

Matt Eicholtz

Matt Eicholtz

on 27 Jun 2013

When I run the code, it appears to do what you are asking. The all(...) part ensures that only rows in which every cell contains characters are deleted.

Rooy

Rooy

on 27 Jun 2013

I must have changed the code, anyway it works.

Thank you

Andrei Bobrov

Andrei Bobrov

Contact us