How to find similar indices in two vector

3 次查看(过去 30 天)
I have a data set where one vector, say 'A' is a subset of vector 'B'. For example vector B = [x,y ,z, A,c , d]
Is there a way i can find the indices of A in B ?
Note: Please keep in mind that vector A is of size 13000 X 1 while vector B is of size 55000 X 1
I have tried xcorr, findsignal and strfind and it's not giving intended results

回答(1 个)

edward holt
edward holt 2020-1-31
There is probably a better (faster) way than this. But it seems to work.
A = randi(1,10000,1);
B = zeros(60000,1);
%inserting A somehwere into B
B(45213:55212) = A;
for i = 1:length(B) - length(A)
if nnz(B(i:i+length(A)-1,:) == A) == length(A)
index = i;
end
end
index
%returns starting point of A within B.

Community Treasure Hunt

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

Start Hunting!

Translated by