Rearranging elements in a 2D array
1 次查看(过去 30 天)
显示 更早的评论
I need some help. I have this code right now:
RandomArray= randi([-100 100],20,5);
RandomArray=sort(RandomArray)
I need to sort RandomArray so that the numbers are in ascending order as in the numbers gets larger going to the right and down the array. How do I do that?
0 个评论
采纳的回答
Roger Stafford
2017-2-20
编辑:Roger Stafford
2017-2-20
RandomArray=sort(RandomArrayI:));
If the original sizes are desired, add this:
RandomArray = reshape(RandomArray,20,5);
If you them ascending to the right and then ascending as you go down, do this instead:
RandomArray = reshape(RandomArray,5,20).';
3 个评论
Walter Roberson
2017-2-21
I think Roger made a typing mistake and it should be
RandomArray=sort(RandomArray(:));
更多回答(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!