Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!v35g2000pro.googlegroups.com!not-for-mail
From: swgillan <swgillan@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Matrix trouble
Date: Tue, 10 Mar 2009 19:42:15 -0700 (PDT)
Organization: http://groups.google.com
Lines: 42
Message-ID: <8dbc1ae0-e0fe-4866-a623-d114b9798ae4@v35g2000pro.googlegroups.com>
References: <gp6nhp$2gd$1@fred.mathworks.com>
NNTP-Posting-Host: 96.50.69.170
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1236739335 9897 127.0.0.1 (11 Mar 2009 02:42:15 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 11 Mar 2009 02:42:15 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: v35g2000pro.googlegroups.com; posting-host=96.50.69.170; 
	posting-account=oG0_2QoAAADs2vBCPqAYFyNKpnhzubZa
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.7) 
	Gecko/2009021910 Firefox/3.0.7 (.NET CLR 3.5.30729),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:523927

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