Question

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));
Was it helpful?

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)

OTHER TIPS

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)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top