Larger size matrix comparison faster elementwise

3 visualizaciones (últimos 30 días)
ashwin sharma
ashwin sharma el 4 de Jul. de 2017
Comentada: Jan el 5 de Jul. de 2017
I want to find the equal elements in two matrices, but size is larger so for loop taking too much time. please suggest how to increase speed.
  5 comentarios
ashwin sharma
ashwin sharma el 5 de Jul. de 2017
number of equal elements divided by the number of all elements
Image Analyst
Image Analyst el 5 de Jul. de 2017
But how do you compare them when they are not the same size? There are ways but you need to tell us. Or do you just want to compare the pairs that are the same size with each other, and not to the different sized ones, like
percentSimilar = sum(sum(m1 == m2)) / numel(m1);

Iniciar sesión para comentar.

Respuestas (3)

Guillaume
Guillaume el 4 de Jul. de 2017
Elementwise comparison has never needed a loop:
A == B
is all that is needed. And if you want the values at the position where they're equal:
A(A == B)
Unless you're talking about another sort of equality (e.g. intersect, which also wouldn't need a loop)
  5 comentarios
Image Analyst
Image Analyst el 5 de Jul. de 2017
Thanks Jan!
Jan
Jan el 5 de Jul. de 2017
@Guillaume: The magic moment of trailing zeros has gone. Walter has been a little bit too slow - I did not think I'd ever say that. Now please restart to answer questions ;-)

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 4 de Jul. de 2017
You only need to shift the 36*79820 matrix 180 by 180 within the larger 36*80000 matrix to check matches or other things at each shift location. That's only 14,400 loop iterations - very small and fast. You can compare in a variety of ways, such as psnr(), isequal(), ssim(), normxcorr2(), etc.

Guillaume
Guillaume el 5 de Jul. de 2017
Still not entirely sure what you call similar, particularly with matrices of different size. If you want the number of elements that are common between the two matrices regardless of location, then as said you can use intersect:
numcommonelements = numel(intersect(matrix1(:), matrix2(:)))
However the above will ignore duplicated elements. If you have duplicated elements, two calls to ismember would do:
numcommonin1 = sum(ismember(matrix1(:), matrix2(:)));
numcommonin2 = sum(ismember(matrix2(:), matrix1(:)));
  1 comentario
Jan
Jan el 5 de Jul. de 2017
Or perhaps:
nCommonCols = numel(intersect(matrix1.', matrix2.', 'rows'))

Iniciar sesión para comentar.

Categorías

Más información sobre Logical 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