how to find a vector's location in another vector

조회 수: 4 (최근 30일)
yaniv friedman
yaniv friedman 2017년 5월 17일
댓글: yaniv friedman 2017년 5월 17일
Hi.
a is a vector sized 1xn A is a vector sized 1xN N>n
how can i find the index of A at which a is located (lets say, the index where a begins)?
for example = a = [1 2 3 4 ]; A = [ 0 4 2 3 1 2 3 5 1 2 3 4 5 6 ] ;
findIndex(a,A) = 9
Thanks!

채택된 답변

Stephen23
Stephen23 2017년 5월 17일
편집: Stephen23 2017년 5월 17일
The simplest and most efficient solution is to use strfind:
>> a = [1,2,3,4];
>> A = [0,4,2,3,1,2,3,5,1,2,3,4,5,6];
>> strfind(char(A),char(a)) % or just strfind(A,a)
ans = 9

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by