sort command

조회 수: 2 (최근 30일)
huda nawaf
huda nawaf 2011년 11월 18일
hi, if i have this array. x=[1 2; 6 8; 1 10;3 2;3 6 ;6 1]; if I sort the first column , can the other columns is arranged according to sorting of first column? as below: 1 2 1 10 3 2 3 6 6 8 6 1
thanks

답변 (2개)

Titus Edelhofer
Titus Edelhofer 2011년 11월 18일
Hi Huda,
take a look at the function sortrows ...
Titus

Jan
Jan 2011년 11월 18일
x = [1 2; 6 8; 1 10; 3 2; 3 6; 6 1];
[x1, index] = sort(x(:, 1));
Xsorted = x(index, :); % or [x1, x(index, 2)];

카테고리

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