to sort a matrix

조회 수: 1 (최근 30일)
Rengin
Rengin 2016년 1월 25일
편집: Stephen23 2016년 1월 25일
% Dear user!
% I have A and B matrices as below
A=[1;2;3;4;5];
B=[12;14;18;16;10];
C=[A B];
% I want to create a D matrix sorting the second column of C matrix as
% below:
D=[5 10;1 12;2 14;4 16;3 18];
% How can I do it? Thank for your help?

채택된 답변

Stephen23
Stephen23 2016년 1월 25일
편집: Stephen23 2016년 1월 25일
Use sortrows with its optional second argument to select the second column:
>> A = [ 1; 2; 3; 4; 5];
>> B = [12;14;18;16;10];
>> sortrows([A,B],2)
ans =
5 10
1 12
2 14
4 16
3 18

추가 답변 (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