Assume a 10 x 3 matrix. Column 1 contains decimal numbers from +1.000 to -1.000. Columns 2 & 3 contain integers. How can I create a new 10 x 3 matrix with the numbers in column 1 arranged from +1 at top to -1 at the bottom?

조회 수: 3 (최근 30일)
Rearrange 10 x 3 matrix so first column decimal numbers are arranged in descending order of magnitude from +1.0 to -1.0

채택된 답변

Stephen23
Stephen23 2015년 3월 12일
You can use sortrows with the second optional argument to select the column and sort direction:
>> A = [0.6,2,4;-0.2,5,3;1,3,8;-1,5,2];
>> sortrows(A,-1)
ans =
1 3 8
0.6 2 4
-0.2 5 3
-1 5 2
  댓글 수: 1
Don Brohaugh
Don Brohaugh 2015년 3월 12일
Thanks! This is exactly what I will need, but the actual matrix size will be 60 x 3. No, it is not homework but for development of a matrix electrical power converter concept that I am working up.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by