returning differences between two matrices

조회 수: 94 (최근 30일)
Zachary Noll
Zachary Noll 2018년 9월 13일
답변: Paolo 2018년 9월 13일
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!

채택된 답변

madhan ravi
madhan ravi 2018년 9월 13일
편집: madhan ravi 2018년 9월 13일
Index = find(A~=B)

추가 답변 (2개)

Matt J
Matt J 2018년 9월 13일
indicator = (A~=B);

Paolo
Paolo 2018년 9월 13일
You can use setdiff:
[~,ia] = setdiff(A,B)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by