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
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!