returning differences between two matrices

57 次查看(过去 30 天)
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 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by