MATLAB Answers

0

returning differences between two matrices

Asked by Zachary Noll on 13 Sep 2018
Latest activity Answered by Paolo
on 13 Sep 2018
I am relatively new to matlab (saw lots of people bashed for asking simple questions..) I need to compare two matrices, and to return true if they are the same. If they aren't identical, I need to have the code return all of the indeces that were not equal:
for instance, I have matrices A = [1,2,3,4,5] and B = [1,2,4,4,5]. I need the code to return either the index of the unequal variable or some other indicating factor.
Thanks!

  0 Comments

Sign in to comment.

Tags

3 Answers

Answer by madhan ravi
on 13 Sep 2018
Edited by madhan ravi
on 13 Sep 2018
 Accepted Answer

Index = find(A~=B)

  0 Comments

Sign in to comment.


Answer by Matt J
on 13 Sep 2018

indicator = (A~=B);

  0 Comments

Sign in to comment.


Answer by Paolo
on 13 Sep 2018

You can use setdiff:
[~,ia] = setdiff(A,B)

  0 Comments

Sign in to comment.