フィルターのクリア

Rearranging elements in a 2D array

1 回表示 (過去 30 日間)
Anonymous Matrix
Anonymous Matrix 2017 年 2 月 20 日
コメント済み: Anonymous Matrix 2017 年 2 月 21 日
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?

採用された回答

Roger Stafford
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
Walter Roberson 2017 年 2 月 21 日
I think Roger made a typing mistake and it should be
RandomArray=sort(RandomArray(:));
Anonymous Matrix
Anonymous Matrix 2017 年 2 月 21 日
thanks so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by