find position of sub array from a larger one

64 visualizaciones (últimos 30 días)
blake
blake el 22 de Nov. de 2019
Editada: Walter Roberson el 22 de Nov. de 2019
Hello, i am now facing a difficult. It is about comparing two arrays. For example i have an array A =[2;4;5;6;2;4;5;6;7;2;4;5;6;], i have another aarray B = [6;7;2;], B is part of A, now i want find the postion of B in A, is there some methods? efficient and cost less memeory?
I have a solution used bsxfun, but it needs creat an aven larger arrya, it costs too much memory and is way too slow. is there some better method? use for loop ?
The reason i did not want a loop is the real A array has about 10^6 values, it is too long. any other efficient method.

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Nov. de 2019
Editada: Walter Roberson el 22 de Nov. de 2019
A =[2;4;5;6;2;4;5;6;7;2;4;5;6;];
B = [6;7;2;];
Bpos_in_A = strfind(A.', B.');
Note: for strfind() to work, the two inputs must be row vectors.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by