MATLAB Answers

## Comparing 2 matrix with not the same dimension

Asked by Pierre Lonfat

### Pierre Lonfat (view profile)

on 28 Oct 2017
Latest activity Commented on by Star Strider

### Star Strider (view profile)

on 29 Oct 2017
Accepted Answer by Star Strider

### Star Strider (view profile)

Lets say I have these 2 following matrix (which are not the same dimension):
A=[2 1 4 3 5 6] B=[5 4 3 1]
My goal is to find the following logical array:
A2=[1 0 0 0 0 1]
where 1 is the logical condition when a value in A is missing in B (again it must check the whole array B because dimension are not the same).
Thank you so much in advance for your answer !
Regards,
Pierre

#### 0 Comments

Sign in to comment.

## 2 Answers

### Star Strider (view profile)

Answer by Star Strider

### Star Strider (view profile)

on 28 Oct 2017
Accepted Answer

Use the ismember function and the logical negation ‘~’ operator:
A=[2 1 4 3 5 6];
B=[5 4 3 1];
A2 = ~ismember(A,B)
A2 =
1×6 logical array
1 0 0 0 0 1

Pierre Lonfat

### Pierre Lonfat (view profile)

on 29 Oct 2017
Works ! Thank you very much !
Star Strider

### Star Strider (view profile)

on 29 Oct 2017
As always, my pleasure!

Sign in to comment.

### Andrei Bobrov (view profile)

Answer by Andrei Bobrov

### Andrei Bobrov (view profile)

on 28 Oct 2017

all(A(:)' ~= B(:))

Pierre Lonfat

### Pierre Lonfat (view profile)

on 29 Oct 2017
Works as well ! THANK YOU !!

Sign in to comment.