matlabcell-arraystrncmp

delete rows with character in cell array


I need some basic help. I have a cell array:

  1. TITLE 13122423
  2. NAME Bob
  3. PROVIDER James

and many more rows with text...

  1. 234 456 234 345
  2. 324 346 234 345
  3. 344 454 462 435

and many MANY (>4000) more with only numbers

  1. text
  2. text

and more text and mixed entries

Now what I want is to delete all the rows where the first column contain a character, and end up with only those rows containing numbers. Row 44 - 46 in this example.

I tried to use

rawdataTruncated(strncmp(rawdataTruncated(:, 1), 'A', 1), :) = [];

but then i need to go throught the whole alphabet, right?


Solution

  • Given data of the form:

    C = {'FIRSTX'   '350.0000' ''        ''        ; ...
         '350.0000' '0.226885' '254.409' '0.755055'; ...
         '349.9500' '0.214335' '254.41'  '0.755073'; ...
         '250.0000' 'LASTX'    ''        ''        };
    

    You can remove any row that has character strings containing letters using isstrprop, cellfun, and any like so:

    index = ~any(cellfun(@any, isstrprop(C, 'alpha')), 2);
    C = C(index, :)
    
    C =
      2×4 cell array
    
        '350.0000'    '0.226885'    '254.409'    '0.755055'
        '349.9500'    '0.214335'    '254.41'     '0.755073'