Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to sort non-ascii characters?
Date: Thu, 16 Oct 2008 07:40:37 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 45
Message-ID: <gd6r5l$4od$1@fred.mathworks.com>
References: <69507506-5d62-4493-b355-9225ed0c8654@v39g2000pro.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1224142837 4877 172.30.248.37 (16 Oct 2008 07:40:37 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 16 Oct 2008 07:40:37 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870065
Xref: news.mathworks.com comp.soft-sys.matlab:495532


damayi <damayi@gmail.com> wrote in message <69507506-5d62-4493-b355-9225ed0c8654@v39g2000pro.googlegroups.com>...
> Dear MATLAB users
> I want to sort a string that contains non-ascii charaters, such as
> Chinese Words.
> I found that MATLAB sort these character according with its double
> value. However, I want to sort them using another rule, for example
> 'PinYin' which represents its pronouncation.
> Here is an example,
> A =3D '=CE=D2=B0=AE=B1=B1=BE=A9=B5=D8=B0=B2=C3=C5'
> Using sort(A), we can get:
> =CE=D2=B0=AE=B1=B1=BE=A9=B5=D8=B0=B2=C3=C5
> 
> this sequence is sorted according to character's double value. Now I
> want to sort it according to its pronouncation, how can I do that?
> 
> Best Regards
> mayi
> 2008-10-16


I am not familiar with chinese and your message screwed up on my newsreader but here's an approach that might work for you. Assume I have an alphabet with six possible characters. 

% You need to define the order of the alphabet
order = {'ff','cc','dd','eee','a','bb'} ;

% My sequence of characters, 
S = {'a','bb','a','cc','bb'}

% The required order after sorting
Srequired = {'cc','a','a','bb','bb'} ;

% The engine
[tf,loc] = ismember(S,order) ;
[unused,si] = sort(loc) ;
Ssorted = S(si) 

% did we arrive at the correct answer
isequal(Ssorted,Srequired) % yes


hth
Jos