MATLAB: Find position of sub array from a larger one

array comparebsxfun

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.

Best Answer

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.