help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Smarter Sort


From: Søren Hauberg
Subject: Re: Smarter Sort
Date: Thu, 25 Aug 2005 15:57:53 +0200
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050818)

Hi,
I haven't thought this through so there's a pretty good chance all I'm saying is nonsense, but here goes... I'd start out by creating a vector containing the numbers you want to sort by, i.e. (assuming your cell array is called C)

for i = 1:length(C)
        A(i) = str2num(C({i}); # This is not good enough
endfor

then call sort with an extra output argument:

[XXX, idx] = sort(A);

And finally sort your cell array using idx,

C = C{idx};

Don't know if it works, but it might get you started,
Søren

Bill Denney wrote:
I'm wanting to sort cell arrays of chars in a smart way. Essentially, I'd like to do something like:

A3B10
A3B9
A10
A1
A2

becomes

A1
A2
A3B9
A3B10
A10

so that it will sort the numeric portions intelligently. Does anyone have a routine that will do that or is there a built-in sort that I don't know of?

Thanks,

Bill




-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]