Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
find seqence of values in an array
조회 수: 1 (최근 30일)
이전 댓글 표시
I have an array of 1000-2000. Within that are some sequences of 4-5 elements. How can I find then?
댓글 수: 2
the cyclist
2016년 3월 1일
So, a small version would be that you have an array A like
A = [1 1 1 1 2 3 4 78 12 16 17 18 19 20 20 20 43]
and you want to find the sequences
1 2 3 4
and
16 17 18 19 20
?
What specifically do you want the output to be?
답변 (1개)
Florian Bendl
2016년 3월 1일
Judging by your example: - Generate a difference vector B = diff(A); - Generate a logical from it B = B == 1; - Loop through the vector and note down when B switches from 0 to 1 and from 1 to 0 respectively. This will give you the beginning and the end of the sequences.- - Having the positions, you can easily choose the longest one.
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!