0

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?

  • Have you looked at using "startsWith"? – Flynn Aug 17 '17 at 20:06
  • What are the actual data types of your cells? Are they all char/string arrays or are they mixed data types? – sco1 Aug 17 '17 at 20:09
  • My data be like this: C = {'TITLE' '13122423'; '3234' '13122423'; 'The end' '13122423'} where I want to delete the entire row which contain any char/string. The outcome would be out= { '3234' '13122423'} –  Aug 17 '17 at 20:19
  • 1
    So every entry in your cell array is a string? – sco1 Aug 17 '17 at 20:24
  • 1
    @J.Birch: We need a bit more clarity on your data, since your post and comment seem to disagree a bit. Does your cell array contain **only** strings (with letters and numbers in them), or does it also contain actual numeric values (**not** strings)? Does any row containing a string with letters (in either column) need to be removed? – gnovice Aug 17 '17 at 20:43

1 Answers1

2

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'
gnovice
  • 125,304
  • 15
  • 256
  • 359
  • I am sorry for the confusion. My real data is like this C = { 'FIRSTX' '350.0000' '' '' ; '350.0000' '0.226885' '254.409' '0.755055' ; '349.9500' '0.214335' '254.41' '0.755073' ; '250.0000' 'LASTX' '' ''} . I want to delete the entire row which contain any char/string in any of the columns. In this case I would end up with : out= {'350.0000' '0.226885' '254.409' '0.755055' ; '349.9500' '0.214335' '254.41' '0.755073'}. –  Aug 17 '17 at 20:58
  • 1
    @J.Birch: Okay, I think that sounds clearer, and I've updated my answer accordingly. For clarity, you should edit your question so it describe the data as you have done in this comment. – gnovice Aug 17 '17 at 21:05
  • That is awesome gnovice. Thanks a lot –  Aug 17 '17 at 21:13