Rearranging elements in a 2D array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Anonymous Matrix
am 20 Feb. 2017
Kommentiert: Anonymous Matrix
am 21 Feb. 2017
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 Kommentare
Akzeptierte Antwort
Roger Stafford
am 20 Feb. 2017
Bearbeitet: Roger Stafford
am 20 Feb. 2017
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 Kommentare
Walter Roberson
am 21 Feb. 2017
I think Roger made a typing mistake and it should be
RandomArray=sort(RandomArray(:));
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!