-1

I've two cell arrays. I need to remove elemtents from the first cell array according to another:

C = {'A1', 'A2', 'A3', 'A4', 'A5', 'A6'}

B = { 'A2','A5'};

I want to get this result:

C = {'A1', 'A3', 'A4', 'A6'}

I tried this but doesn't work

C = A(~find(A, B));
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
TimeIsNear
  • 711
  • 4
  • 19
  • 38

2 Answers2

3

find function takes only one argument and returns indexes only of True-values(non-zero for numeric or nonempty for cell-array).

For your purpose look at setdiff function:

C = setdiff(A,B)
Andrey Shokhin
  • 11,250
  • 1
  • 16
  • 15
3
C = {'A1', 'A2', 'A3', 'A4', 'A5', 'A6'};
B = { 'A2','A5'};

You need the ismember function for cell arrays:

>> ismember(C, B)
ans =
    0   1   0   0   1   0

So this we invert and find:

C(find(~ismember(C, B)))
Noctua
  • 5,058
  • 1
  • 18
  • 23