Path: news.mathworks.com!not-for-mail
From: "kaori Joo" <rocio.joo@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: sorting problems
Date: Mon, 16 Feb 2009 20:09:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 38
Message-ID: <gnch4t$b62$1@fred.mathworks.com>
References: <gk5u0u$m34$1@fred.mathworks.com> <gk5upd$dvg$1@fred.mathworks.com>
Reply-To: "kaori Joo" <rocio.joo@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1234814941 11458 172.30.248.37 (16 Feb 2009 20:09:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 16 Feb 2009 20:09:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1662292
Xref: news.mathworks.com comp.soft-sys.matlab:518664


Merci for your help. Sorry for not answering before.

I managed to sort alphabetically by the second column, but when I try to do so by dates (I first converted it using datenum), I get this error:

??? Error using ==> char
Cell elements must be character arrays.

Error in ==> sortrows>sort_cell_back_to_front at 129
    tmp = char(x(ndx,k));

Error in ==> sortrows at 90
        ndx = sort_cell_back_to_front(x_sub, col);

I'm trying to fix it but I can't find a way, yet. Any ideas? (I'd really apreciate it).

"Jiro Doke" <jiro.doke@mathworks.com> wrote in message <gk5upd$dvg$1@fred.mathworks.com>...
> "kaori Joo" <rocio.joo@gmail.com> wrote in message <gk5u0u$m34$1@fred.mathworks.com>...
> > Hi,
> > I have a matrix like this:
> >   Name                       Size              Bytes  Class 
> > data                    3653x24            6436668  cell                
> > 
> > The first column has integers, the second one names (strings), the third one and the fourth one have dates (in string format), and all the other ones have just numbers. I want to sort the matrix by the alphabetical order of the column of names (second column), and then by dates (third column), and then the seventh column.
> > 
> > What should I do?
> > 
> > Kaori
> 
> Kaori,
> 
> You can use SORTROWS.
> 
> sortedData = sortrows(data, [2 3 7]);
> 
> *note: the dates will be sorted alphabetically. You may need to convert the dates to numbers (using DATENUM) before you do the sort.
> 
> 
> jiro