필터 지우기
필터 지우기

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 CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by