Search code examples
arraysmatlabcell-array

Remove elements from first cell array according to another


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

Solution

  • 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)