Comparing two matriced

5 visualizaciones (últimos 30 días)
joseph Frank
joseph Frank el 10 de Mzo. de 2011
Comentada: Kiarash Ahi el 21 de Jul. de 2014
Hi,
Is there a fast way to compare the differences between two matrices with the same dimension:
example Assume A and B each is a 1000x1000 matrix. Is there a way to find where A and B differ in one step?

Respuestas (4)

Jan
Jan el 10 de Mzo. de 2011
And if the matrices are results of floating point computation a certian relative or absolute tolerance might be helpful:
abs_d = (A - B) < Tol
rel_d = ((A - B) ./ min(A, B)) < Tol
And now the same tools as replied by Walter, Sean and Matt can be applied.

Walter Roberson
Walter Roberson el 10 de Mzo. de 2011

Sean de Wolski
Sean de Wolski el 10 de Mzo. de 2011
The logical matric
ABne = A~=B
or if you need the indices
[r c] = find(ABne);

Matt Fig
Matt Fig el 10 de Mzo. de 2011
And a visual method:
spy(A~=B)
And a quick method to count the number of locations where A is not equal to B:
nnz(A~=B)
  8 comentarios
Jan
Jan el 10 de Mzo. de 2011
NNZ is *much* faster in SSE, especially if the data are aligned at 128 bit boundaries.
Sean de Wolski
Sean de Wolski el 10 de Mzo. de 2011
I find it funny how the help for nnz says:
The density of a sparse matrix S is nnz(S)/prod(size(S))"
But M-Lint now says:
numel(S) is faster than prod(size(S))"

Iniciar sesión para comentar.

Categorías

Más información sobre Sparse Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by