From: Aui on
I would like to sort data in Nx3 matrix, named A below:

A =
1 200 300
2 200 200
3 100 100

I would like to sort this matrix by 2nd column first, then follow by 3rd column. I don't want MATLAB to return the result independently because the data are associated.

What I expected is to sort the 2nd column first with the 1st and 3rd column are changed order according to the sorted result. After that I would like to sorted the data again according to the 3rd column. So, the final result would be as below:

3 100 100
2 200 200
1 200 300

I see the sort function in Matlab is kind of sort individually and that cannot apply for my case.

Thank you very much for your suggestion.
From: Aui on
Can anybody suggest how can I sort for the 2nd time depending on the 3rd column?

A = [1 200 300;
2 200 200;
3 100 100;]

>> [d1,d2] = sort(A(:,2))
>> A(d2,:)

Now my result is
ans =

3 100 100
1 200 300
2 200 200

It's nearly complete except the 3rd column.
I don't know how can I further sort the 3rd column to finally produce:

> 3 100 100
> 2 200 200
> 1 200 300

Please suggest. Thank you.
From: Aui on
Can anybody suggest how can I sort for the 2nd time depending on the 3rd column?

A = [1 200 300;
2 200 200;
3 100 100;]

>> [d1,d2] = sort(A(:,2))
>> A(d2,:)

Now my result is
ans =

3 100 100
1 200 300
2 200 200

It's nearly complete except the 3rd column.
I don't know how can I further sort the 3rd column to finally produce:

> 3 100 100
> 2 200 200
> 1 200 300

Please suggest. Thank you.
From: Jan Simon on
Dear Aui!

> A =
> 1 200 300
> 2 200 200
> 3 100 100
>
> I would like to sort this matrix by 2nd column first, then follow by 3rd column.

help sortrows

Kind regards, Jan
From: Steven Lord on

"Aui " <littlebearproject(a)gmail.com> wrote in message
news:hjs301$8l$1(a)fred.mathworks.com...
>I would like to sort data in Nx3 matrix, named A below:
>
> A = 1 200 300
> 2 200 200
> 3 100 100
>
> I would like to sort this matrix by 2nd column first, then follow by 3rd
> column. I don't want MATLAB to return the result independently because the
> data are associated.
>
> What I expected is to sort the 2nd column first with the 1st and 3rd
> column are changed order according to the sorted result. After that I
> would like to sorted the data again according to the 3rd column. So, the
> final result would be as below:
>
> 3 100 100
> 2 200 200
> 1 200 300
>
> I see the sort function in Matlab is kind of sort individually and that
> cannot apply for my case.

HELP SORTROWS.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ