How can I order consecutive numbers?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello everyone,
I need to reorder the values in A as follow (B):
(A) (B)
1 1
2 2
3 2
4 3
4 4
6 4
6 6
5 6
6 6
5 5
2 5
How can i do it? Thank you very much!
댓글 수: 2
Walter Roberson
2020년 6월 8일
I think it is a "stable" sort. The elements appear in the final vector in the same order they are introduced in the original. You can get the elements in that order with unique() with 'stable' option, but I am still working on a good way to get the desired final result.
채택된 답변
Walter Roberson
2020년 6월 8일
[~,~,R] = unique(A, 'stable');
[~,idx] = sort(R);
B = A(idx)
... or at least it worked for that example.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!