Thread Subject: How to sort non-ascii characters?

Subject: How to sort non-ascii characters?

From: damayi

Date: 16 Oct, 2008 06:29:18

Message: 1 of 2

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

Subject: How to sort non-ascii characters?

From: Jos

Date: 16 Oct, 2008 07:40:37

Message: 2 of 2

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


Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com