Find indicies of unsorted locations in an array
조회 수: 10 (최근 30일)
이전 댓글 표시
I have a long array, e.g.
A=[ 1 2 5 8 7 9 110 100]
I want to get an array B, which contains the left-index of the positions where the array is not sorted (the array is supposed to be sorted from the lowest value on the left, to the highest value on the right), namely
B=[4,7]
How can I do that without using loops?
Another example, just to make the point clear: I assume that the array is more-or-less already sorted, so AA=[-1 1 3 2 0] does not occur, but AA=[-1 1 3 2 5] does.
The latter will yield: B=[3].
Also AA=[-1 1 8 2 3] does not occur. I assume that if there are non-sorted positions, then by switching the locations of only nearest neighbours (i, i+1) I can make the array sorted again.
Thanks!
댓글 수: 3
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!