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

Delete rows with strings for a cell array

Asked by Rooy on 26 Jun 2013

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




No products are associated with this question.

1 Answer

Answer by Andrei Bobrov on 26 Jun 2013
Edited by 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),:);


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


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 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 on 27 Jun 2013

I must have changed the code, anyway it works.

Thank you

Andrei Bobrov

Contact us