How can I order consecutive numbers?
2 次查看(过去 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!