I have a matrix such as A=[1 2 3;1 3 5] and I want to determine which row(s) is(are) totally contained in one (or more) single row(s) of another matrix such as B=[1 4 3 2 8;1 4 5 9;1 2 5 8 9]. In this example, row 1 of A is contained is the first row of B, but second row of A is NOT contained in a single row of B (elements 1 and 3 are in first row of B, and element 5 is in second). I know I could use ISMEMBER function for each row of A, but my matrices are too large, and a loop would take too long. Does anyone have a solution for that without a FOR-END or WHILE-END loop?

 Respuesta aceptada

Image Analyst
Image Analyst el 16 de Feb. de 2017

1 voto

How large? What are your actual, typical size dimensions for A and B? I just did a for loop with a million iterations and the for loop itself (not with ismember in it) took 0.002 seconds.
One way to do it with 2-D arrays is to use normalized cross correlation with normxcorr2(). See attached demo.

5 comentarios

Alberto Rocha
Alberto Rocha el 17 de Feb. de 2017
Editada: Alberto Rocha el 17 de Feb. de 2017
A is 1365x11 and B is 26000x15. Do you know a way to do that faster? The lines of code that I wrote already took more than 4 hours.
PS: Let me explain better: I have more than 20000 matrices the same size as A, and, for each of them, I have to do what I explained above. The loop for EACH matrix like A is quick, but taking into account all of them, it takes too long.
Image Analyst
Image Analyst el 17 de Feb. de 2017
Did you even try normxcorr2() like I suggested? Your images aren't that big so for one pair, it shouldn't take that long. For my images, which are bigger than yours, it took 0.696949 seconds. So for 20,000 of them it would take 232 minutes, or almost 4 hours. You may be faster since your images are a lot smaller, but for 20,000 images, it will still take a long time. You may just have to live with it.
Alberto Rocha
Alberto Rocha el 18 de Feb. de 2017
I tried, but I couldn't understand what this function does. I'll keep trying. Would you have a link to a simpler example ? (the one in help file is too complicated for me). Thanks
Image Analyst
Image Analyst el 18 de Feb. de 2017
You could use the moving SAD method - very accurate, but it might be slow.
Alberto Rocha
Alberto Rocha el 22 de Feb. de 2017
Thanks a lot. I'll try to learn how to use this function.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 16 de Feb. de 2017

Comentada:

el 22 de Feb. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by