|
On Mar 10, 2:54=A0pm, "Niall Heavey" <niallhea...@eircom.net> wrote:
> Hi all,
>
> Just wondering if there is any way of using the sort function (or if ther=
e is any other way) to do the following.
>
> I am making a matrix.... lets say x =3D [4 2 6 -1; 6 2 5 1]
> x =3D
> 4 2 6 -1
> 6 2 5 1
>
> I want to try and sort out the top row in ascending order that will keep =
its corresponding y value under it.
> For example, the sorted matrix, we can call it y, should be the following=
;
> y =3D
> -1 2 4 6
> 1 2 6 5
>
> I hope that makes sense.
>
> Anyone any idea how I might go about doing this?
>
> Regards.
I am not sure if this applies to every case, but I just through this
up in matlab
x =3D [4 2 6 -1; 6 2 5 1]
x =3D
4 2 6 -1
6 2 5 1
>> sortrows(x')' %transpose x, and then sortrows on it (column 1 ascending =
is default) then transpose it back.
ans =3D
-1 2 4 6
1 2 6 5
|