sort command

2 Ansichten (letzte 30 Tage)
huda nawaf
huda nawaf am 18 Nov. 2011
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

Antworten (2)

Titus Edelhofer
Titus Edelhofer am 18 Nov. 2011
Hi Huda,
take a look at the function sortrows ...
Titus

Jan
Jan am 18 Nov. 2011
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)];

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by