Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
alphabetic ordering

Subject: alphabetic ordering

From: kaori Joo

Date: 8 Jan, 2009 22:17:02

Message: 1 of 5

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

Subject: alphabetic ordering

From: Jiro Doke

Date: 8 Jan, 2009 22:30:05

Message: 2 of 5

"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

Subject: sorting problems

From: kaori Joo

Date: 16 Feb, 2009 20:09:01

Message: 3 of 5

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

Subject: sorting problems

From: us

Date: 16 Feb, 2009 20:14:02

Message: 4 of 5

"kaori Joo"
> 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...

can you show a very small example of your data...
us

Subject: sorting problems

From: kaori Joo

Date: 23 Feb, 2009 22:30:19

Message: 5 of 5

Hi, I give you 4 lines (with 11 columns each)

22 '''ALETA AZUL I, LOBOS DE AFUERA ' '''21/03/2007 21:00:0' '''23/03/2007 02:00:0' 0,0833333333333333 3 1 '''22/03/2007 06:53:0' '''22/03/2007 07:08:0' 0,0104166666666667 72
22 '''ALETA AZUL I, LOBOS DE AFUERA ' '''21/03/2007 21:00:0' '''23/03/2007 02:00:0' 0,0833333333333333 3 2 '''22/03/2007 11:00:0' '''22/03/2007 12:30:0' 0,0625000000000000 72
22 '''ALETA AZUL I, LOBOS DE AFUERA ' '''21/03/2007 21:00:0' '''23/03/2007 02:00:0' 0,0416666666666667 3 3 '''22/03/2007 13:46:0' '''22/03/2007 15:35:0' 0,0756944444444444 72
22 '''ALETA AZUL I, LOBOS DE AFUERA ' '''23/03/2007 03:30:0' '''23/03/2007 15:05:0' 0,00694444444444444 2 1 '''23/03/2007 06:37:0' '''23/03/2007 09:05:0' 0,102777777777778 70

Thanks!

"us " <us@neurol.unizh.ch> wrote in message <gnchea$up$1@fred.mathworks.com>...
> "kaori Joo"
> > 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...
>
> can you show a very small example of your data...
> us

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us