MATLAB Answers

Rooy
0

Delete rows with strings for a cell array

Asked by Rooy
on 26 Jun 2013
Latest activity Commented on by Sonisa
on 25 Feb 2016

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

Products

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),:);

or

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

  4 Comments

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

Sonisa
on 25 Feb 2016

I have this format

'Time' 'DOY' 'VWC05' 'VWC10' 'VWC20' 'VWC50' 'T05' 'T10' 'T20' 'T50' 'PAW40' 'PAW65' '#' '#' 'cm^3/cm^3' 'cm^3/cm^3' 'cm^3/cm^3' 'cm^3/cm^3' '°C' '°C' '°C' '°C' 'mm' 'mm'

Which I want to delete it. They are on every 600th row, sometimes in 590th row. How do I delete it so that I can get the value that i want?

Thank you in advance.


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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!