Tideman,
Thanks a lot, I thought of this, but did not think there was any way to keep track of the changing index. This is awesome, thanks for the help.
TideMan <mulgor@gmail.com> wrote in message <be6d7fe6-08f8-42ca-98a3-ae4c6032e38c@googlegroups.com>...
> On Sunday, August 4, 2013 3:32:06 PM UTC+12, Larry Rose wrote:
> > hello, I need to sort dates and need to have string data be sorted along with it's corresponding date. I don't think I can use chars because the text data are not all the same length and don't think I can use cells since I can not include cells in a rowsort(x,[1]) function. Someone must know how to do this and I will be most grateful for any help.
> >
> >
> >
> > Here is what I have been working with:
> >
> > x=datenum(2008,08,05)
> >
> > y=datenum(2007,07,04)
> >
> > z=datenum(2006,02,03)
> >
> >
> >
> > xyz={datestr(y);datestr(x);datestr(z)} % matlab will sort this
> >
> > % c=char('tim','clare','sin')% no, char arrays are sensative to length of the word
> >
> > % c={'tim';'clare';'sin'} % no, can't row sort a cell
> >
> > xyzc=[xyz,c] %
> >
> > rowsort(xyzc,[1]) %i can't get this to work
> >
> >
> >
> >
> >
> > Thank you,
> >
> > larry
>
> xyz=[x;y;z]; % Compose a vector of times
> c={'tim';'clare';'sin'}; % and corresponding cell array of strings
>
> Sort the numbers and keep track using indices:
> [~,indx]=sort(xyz);
>
> Sorted arrays are:
> c(indx)
> xyz(indx)
Thanks a lot, I thought of this, but did not think there was any way to keep track of the changing index. This is awesome, thanks for the help.
TideMan <mulgor@gmail.com> wrote in message <be6d7fe6-08f8-42ca-98a3-ae4c6032e38c@googlegroups.com>...
> On Sunday, August 4, 2013 3:32:06 PM UTC+12, Larry Rose wrote:
> > hello, I need to sort dates and need to have string data be sorted along with it's corresponding date. I don't think I can use chars because the text data are not all the same length and don't think I can use cells since I can not include cells in a rowsort(x,[1]) function. Someone must know how to do this and I will be most grateful for any help.
> >
> >
> >
> > Here is what I have been working with:
> >
> > x=datenum(2008,08,05)
> >
> > y=datenum(2007,07,04)
> >
> > z=datenum(2006,02,03)
> >
> >
> >
> > xyz={datestr(y);datestr(x);datestr(z)} % matlab will sort this
> >
> > % c=char('tim','clare','sin')% no, char arrays are sensative to length of the word
> >
> > % c={'tim';'clare';'sin'} % no, can't row sort a cell
> >
> > xyzc=[xyz,c] %
> >
> > rowsort(xyzc,[1]) %i can't get this to work
> >
> >
> >
> >
> >
> > Thank you,
> >
> > larry
>
> xyz=[x;y;z]; % Compose a vector of times
> c={'tim';'clare';'sin'}; % and corresponding cell array of strings
>
> Sort the numbers and keep track using indices:
> [~,indx]=sort(xyz);
>
> Sorted arrays are:
> c(indx)
> xyz(indx)