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?

 Réponse acceptée

Roger Stafford
Roger Stafford le 20 Fév 2017
Modifié(e) : Roger Stafford le 20 Fév 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 commentaires

Anonymous Matrix
Anonymous Matrix le 21 Fév 2017
sorry i'm a bit confused but what's the first line of code for?
I think Roger made a typing mistake and it should be
RandomArray=sort(RandomArray(:));
Anonymous Matrix
Anonymous Matrix le 21 Fév 2017
thanks so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by