compare two matrices

Ellen (view profile)

on 23 May 2011
Latest activity Commented on by Salah Alhaithemy

Salah Alhaithemy (view profile)

on 10 Mar 2016
Accepted Answer by Sean de Wolski

Sean de Wolski (view profile)

Hi,

I want to compare two matrices for equal values, and I want to know if there is a build-in function to do this. Ihaven't been able to find it in the MATLAB help.

example: A=[1 2 3; 4 5 6; 7 8 9] B=[9 8 7; 6 5 4; 3 2 1] this should return something like result=[0 0 0;0 1 0;0 0 0] so I can see there is an equal number on the same position in both matrices and the position that it is in.

Thanks!

Ellen

João Peixoto

João Peixoto (view profile)

on 13 Oct 2015

have you tried? result = A==B;

Products

No products are associated with this question.

Sean de Wolski (view profile)

on 23 May 2011

```result = A==B;
```

Ellen

on 23 May 2011

Thanks so much.

Sincloe Brans

Sincloe Brans (view profile)

on 12 Aug 2014

This doesn't work for two matrix with different dimensions, any way to compare two matrix with different rows and same number of column (eg A=50*16 vs B=100*16)?

Sean de Wolski

Sean de Wolski (view profile)

on 12 Aug 2014
```isequal
```

Kiarash Ahi (view profile)

on 21 Jul 2014
Edited by Kiarash Ahi

Kiarash Ahi (view profile)

on 21 Jul 2014

How if I want two compare the two matrices and get only one digit; I mean 1 if both were the same and 0 if at least two element of the matrices differ?

Kiarash Ahi

Kiarash Ahi (view profile)

on 21 Jul 2014

I have just found the answer to my question:

` find(A~=B)`
Niko

Niko (view profile)

on 12 Aug 2014
```isequal(A,B)
```
Salah Alhaithemy

Salah Alhaithemy (view profile)

on 10 Mar 2016

isempty(find(A==B))

Join the 15-year community celebration.

Play games and win prizes!

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