help-octave
[Top][All Lists]
Advanced

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

Re: Sorting of words


From: Gabriel Panzenboeck
Subject: Re: Sorting of words
Date: Fri, 25 Feb 2000 19:48:40 +0100 (CET)

> > > I use Octave 2.0.16 and I have the following problem. I want to sort
> > > alphabetically the words: "apple", "dog", "long". I tried with SORT
> > > function without success. How can I solve this problem?

> > a quick and dirty solution:
> > a=['dog';'long';'apple']
> > [s,i]=sort(toascii(a(:,1)))
> > b=a(i,:)

> Thanks for your answer. However there is a little problem.
> In this special case your program works well. When I typed 'adog',
> 'along','aapple' instead of 'dog','long','apple' it produced a wrong
> output.
> Could you modify your "dirty solution" for general case?

i guess etiennes solution is the more professionell one, nevertheless i
worked out an even dirtier solution - but i think it works:

--
a=['adog';'along';'aapple'];
s=toascii(a);
n=columns(s);
for i= n:-1:1
  [so,in]= sort(s(:,i));
  s=s(in,:);
endfor
s=setstr(s)
--
yields...
--
octave:2> s
s =

aapple
adog
along
--

..just my .02 eurocents 

g.

| address@hidden
| http://come.to/panzenboeck
| PGP-encrypted mail appreciated
|
| Braunspergengasse 9/15
| A -1100 Wien, Austria



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

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



reply via email to

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