1

How do I return only the rows of a matrix 'A' that not contain some values (These values ​​are an array 'B')?

  A = {'A1',  5  'P01,P02,P03,P04,P07'; 
        'A2'  7,  'P07,P10';
        'A3'  8,  'P07,P09';
        'A4'  8,  'P10,P11'};

    B = { 'P07'; 'P10'; 'P11'};

I need to return only:

'A1'  ( P01,P02,P03,P04 not exist in B)
'A3'  (P09 not exist in B)

Thanks in advance for your help

TimeIsNear
  • 711
  • 4
  • 19
  • 38

1 Answers1

3

Since you are dealing with weirdly shaped cell arrays and some strange string operations, I do not know how to solve this cleanly with one statement. You can try the following loop:

R = {};
for i = 1 : size(A, 1)
    test = strsplit(A{i, 3}, ',');
    for j = 1 : length(test)
        if nnz(strcmp(B, test{j})) == 0
            R = [R; A(i, 1)];
            break;
        end
    end
end

The result is:

R = 

    'A1'
    'A3'

Of course these calculations could be made much faster if it was possible to work with just the numerical components of each search string in an actual matrix rather than cell arrays of strings.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264