Find a specific array within a larger array
조회 수: 24 (최근 30일)
이전 댓글 표시
Hi all,
I am struggling with a problem. I have a large array, for example a = [11 12 13 14 15 16 13 14], and I want to find the index for a specfic sub sequence eg. b = [13 14 15]. So in this example I would want the index of 3 to indicate the position that b started in a. I dont want to know the indices of a that any number within b, i instead need them to be specifically in the order b, ie I dont care about the last two 13 14 numbers in a as it isnt the entirety of b.
I know I could simply do a loop that checks b against a subset of a and loops throughout the whole of a but this seems a little ineffectient if a is very big, (in my acutal code a is many 100,000's of numbers in length).
Is there a more efficent way, any help is appreiacted.
Thanks
J
댓글 수: 2
Dyuman Joshi
2023년 11월 28일
이동: Dyuman Joshi
2023년 11월 28일
a = [11 12 13 14 15 16 13 14]
b = [13 14 15]
strfind(a, b)
Dyuman Joshi
2023년 11월 28일
이동: Dyuman Joshi
2023년 11월 28일
Ah, it seems that I'm just a little late to the party.
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!