Sorting duplicate incremental array elements
4 次查看(过去 30 天)
显示 更早的评论
I was curious if there is a more efficient method for performing the following result:
>> x = 1:4;
>> xx = sort(x([1:end,1:end]))
1 1 2 2 3 3 4 4
If an alternative method is applicable to the previous example, consider also the more general case:
>> x = 1:4;
>> n = 2;
>> xn = sort(x(repmat([1:end],[1,n])))
To me it seems like the use of the sort command is inefficient and could cause notable performance reductions when working with larger incremental lists.
I would appreciate any suggestions.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!