Find indicies of unsorted locations in an array

2 次查看(过去 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!

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by