How to find similar indices in two vector

조회 수: 1 (최근 30일)
Shekhar Vats
Shekhar Vats 2020년 1월 31일
답변: edward holt 2020년 1월 31일
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.

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by