From: Ulrik Nash on
Hi everyone,

I have a matrix, A, as follows:

3 1 2
1 3 1
4 5 2

Now I wish to sort A horizontally according to the top row, so that the largest value in the top row is in the top right corner. The final result should look like this:

1 2 3
3 1 1
5 2 4

How is this done?

Regards, Ulrik.
From: someone on
"Ulrik Nash" <uwn(a)sam.sdu.dk> wrote in message <hr9khc$74q$1(a)fred.mathworks.com>...
> Hi everyone,
>
> I have a matrix, A, as follows:
>
> 3 1 2
> 1 3 1
> 4 5 2
>
> Now I wish to sort A horizontally according to the top row, so that the largest value in the top row is in the top right corner. The final result should look like this:
>
> 1 2 3
> 3 1 1
> 5 2 4
>
> How is this done?
>
> Regards, Ulrik.

>> A

A =

3 1 2
1 3 1
4 5 2

>> B = sortrows(A')'

B =

1 2 3
3 1 1
5 2 4
From: Roger Stafford on
"someone" <someone(a)somewhere.net> wrote in message <hr9mc1$a4o$1(a)fred.mathworks.com>...
> ........
> >> B = sortrows(A')'
> ........

It depends on what Ulrik wants to happen in case of ties in that first row. If he wants to continue to sort in other rows based on those "tied" columns, then that would be correct, but if the desire is to leave columns unchanged with ties in the first row, then he should use this:

B = sortrows(A',1)';

An example would be

A = 2 2
3 1
2 5 .

Does he want

B = 2 2
1 3
5 2

with sortrows(A')' or

B = 2 2
3 1
2 5

with sortrows(A',1)' ?

Roger Stafford
From: Ulrik Nash on
"Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <hr9ou0$15o$1(a)fred.mathworks.com>...
> "someone" <someone(a)somewhere.net> wrote in message <hr9mc1$a4o$1(a)fred.mathworks.com>...
> > ........
> > >> B = sortrows(A')'
> > ........
>
> It depends on what Ulrik wants to happen in case of ties in that first row. If he wants to continue to sort in other rows based on those "tied" columns, then that would be correct, but if the desire is to leave columns unchanged with ties in the first row, then he should use this:
>
> B = sortrows(A',1)';
>
> An example would be
>
> A = 2 2
> 3 1
> 2 5 .
>
> Does he want
>
> B = 2 2
> 1 3
> 5 2
>
> with sortrows(A')' or
>
> B = 2 2
> 3 1
> 2 5
>
> with sortrows(A',1)' ?
>
> Roger Stafford


Hi Roger,

That is correct:

B = sortrows(A',1)';

Thanks for the help both of you! Much appreciated.

Ulrik.
 | 
Pages: 1
Prev: object recognition
Next: Supervised learning