Re: Using sortrows on mixed-type cell arrays



Thank you for your reply Jos, I'll try and explain:

I am trying to sort a log file with the fields:

<time> <user> <url>

I read the log file into a Matlab cell array, everthing is string
apart from <time> which has been converted using timevec - I
will use plain text below though to illustrate what I am trying to
do.

Here is an example:

15.05.2006 23:30 Bob <http://somesite.com/>
15.05.2006 23:29 Cat <http://anothersite.com/>
15.05.2006 23:31 Bob <http://pr0nsite.com/>
15.05.2006 04:20 Cat <http://newssite.com/>

I now want to sort the rows of the array first by <user> then
by <time> ... for the above example:

sorting by <user> results in (Bob "<" Cat):

15.05.2006 23:30 Bob <http://somesite.com/>
15.05.2006 23:31 Bob <http://pr0nsite.com/>
15.05.2006 23:29 Cat <http://anothersite.com/>
15.05.2006 04:20 Cat <http://newssite.com/>

Next, the array should be sorted by time so in the example the two
Cat entries are swapped since 04:20 < 23.29 to result in:

15.05.2006 23:30 Bob <http://somesite.com/>
15.05.2006 23:31 Bob <http://pr0nsite.com/>
15.05.2006 04:20 Cat <http://newssite.com/>
15.05.2006 23:29 Cat <http://anothersite.com/>

The problem - again - is that <time> is numerical whereares the
remaining fields are strings ... so SORTROWS doesn't work.

This is a pretty common task I guess so there's got be some simple
solution ...

Another thing, I really like MATLAB central - but would it be too
hard to have it use a fixed-width font ... for example code it would
be great.
.



Relevant Pages

  • sort 1-D array of doubles for Olaf Schmidt
    ... A few weeks Olaf Schmidt posted a VB6 routine to sort a 1-D array of strings very fast indeed. ... fastest way to change case of string. ... Dim i As Long, j As Long, Lo As Long, Hi As Long, StPtr As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: Collection Structure
    ... property StringID you want ... where inarr is the String array and outarr is an array of longs containing ... needs to sort the input array keeping track of the original position (I use ...
    (microsoft.public.vb.com)
  • Re: About word frequency
    ... Use the split function to turn the string into an array. ... Sort the array. ... For each sLine in aList ...
    (microsoft.public.scripting.vbscript)
  • Re: Quick method to sort a list of strings?
    ... 'split string into an array around so each line is a seperate item ... the cell may represent the number of purchases by ... I do not have all the these comments stored in an array ... separate entities and sort them in alpha-numeric order? ...
    (microsoft.public.excel.programming)
  • RE: Quick method to sort a list of strings?
    ... 'split string into an array around so each line is a seperate item ... the cell may represent the number of purchases by ... I do not have all the these comments stored in an array ... separate entities and sort them in alpha-numeric order? ...
    (microsoft.public.excel.programming)