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 Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by