function opposite of ismember?

on 8 Aug 2012

Matt Fig (view profile)

Hi, Is there a function that does the opposite of 'ismember' i.e. something like, 'isnotmember'?

So if:

```    A = [1:10]
B = [2,5,7]```
```ismember(A,B)
```
```ans =
```
`     0     1     0     0     1     0     1     0     0     0`

```isnotmember(A,B)
ans =
1     0     1     1     0     1     0     1     1     1
```

Products

No products are associated with this question.

Matt Fig (view profile)

on 8 Aug 2012
Edited by Matt Fig

Matt Fig (view profile)

on 8 Aug 2012

Use the logical negation symbol

```~ismember(A,B)
```

or the functional form:

```not(ismember(A,B))
```

Lalit Patil

Lalit Patil (view profile)

on 25 Dec 2012
``` A = [1:10];
B = [2,5,7];
[flag,index] = ismember(B,A);
v = A(index(flag))```

I tried and find that i am able to find flag and index of ismember(B,A) function.

But, i can not find for ~ismember(A,B) and not(ismember(A,B))

So, how to find it..?

Andrei Bobrov

Andrei Bobrov (view profile)

on 25 Dec 2012
```flag = ~ismember(B,A);
index = find(flag);
```

or

```[out,index] = setdiff(A,B);
```
Lalit Patil

Lalit Patil (view profile)

on 25 Dec 2012

It works by

``` flag = ~ismember(A,B);
index = find(flag);```

Thank you.

Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi