<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237638</link>
    <title>MATLAB Central Newsreader - How to sort non-ascii characters?</title>
    <description>Feed for thread: How to sort non-ascii characters?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 16 Oct 2008 06:29:18 -0400</pubDate>
      <title>How to sort non-ascii characters?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237638#605601</link>
      <author>damayi</author>
      <description>Dear MATLAB users&lt;br&gt;
I want to sort a string that contains non-ascii charaters, such as&lt;br&gt;
Chinese Words.&lt;br&gt;
I found that MATLAB sort these character according with its double&lt;br&gt;
value. However, I want to sort them using another rule, for example&lt;br&gt;
'PinYin' which represents its pronouncation.&lt;br&gt;
Here is an example,&lt;br&gt;
A =3D '=CE=D2=B0=AE=B1=B1=BE=A9=B5=D8=B0=B2=C3=C5'&lt;br&gt;
Using sort(A), we can get:&lt;br&gt;
=CE=D2=B0=AE=B1=B1=BE=A9=B5=D8=B0=B2=C3=C5&lt;br&gt;
&lt;br&gt;
this sequence is sorted according to character's double value. Now I&lt;br&gt;
want to sort it according to its pronouncation, how can I do that?&lt;br&gt;
&lt;br&gt;
Best Regards&lt;br&gt;
mayi&lt;br&gt;
2008-10-16</description>
    </item>
    <item>
      <pubDate>Thu, 16 Oct 2008 07:40:37 -0400</pubDate>
      <title>Re: How to sort non-ascii characters?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237638#605613</link>
      <author>Jos </author>
      <description>damayi &amp;lt;damayi@gmail.com&amp;gt; wrote in message &amp;lt;69507506-5d62-4493-b355-9225ed0c8654@v39g2000pro.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; Dear MATLAB users&lt;br&gt;
&amp;gt; I want to sort a string that contains non-ascii charaters, such as&lt;br&gt;
&amp;gt; Chinese Words.&lt;br&gt;
&amp;gt; I found that MATLAB sort these character according with its double&lt;br&gt;
&amp;gt; value. However, I want to sort them using another rule, for example&lt;br&gt;
&amp;gt; 'PinYin' which represents its pronouncation.&lt;br&gt;
&amp;gt; Here is an example,&lt;br&gt;
&amp;gt; A =3D '=CE=D2=B0=AE=B1=B1=BE=A9=B5=D8=B0=B2=C3=C5'&lt;br&gt;
&amp;gt; Using sort(A), we can get:&lt;br&gt;
&amp;gt; =CE=D2=B0=AE=B1=B1=BE=A9=B5=D8=B0=B2=C3=C5&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; this sequence is sorted according to character's double value. Now I&lt;br&gt;
&amp;gt; want to sort it according to its pronouncation, how can I do that?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Best Regards&lt;br&gt;
&amp;gt; mayi&lt;br&gt;
&amp;gt; 2008-10-16&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
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. &lt;br&gt;
&lt;br&gt;
% You need to define the order of the alphabet&lt;br&gt;
order = {'ff','cc','dd','eee','a','bb'} ;&lt;br&gt;
&lt;br&gt;
% My sequence of characters, &lt;br&gt;
S = {'a','bb','a','cc','bb'}&lt;br&gt;
&lt;br&gt;
% The required order after sorting&lt;br&gt;
Srequired = {'cc','a','a','bb','bb'} ;&lt;br&gt;
&lt;br&gt;
% The engine&lt;br&gt;
[tf,loc] = ismember(S,order) ;&lt;br&gt;
[unused,si] = sort(loc) ;&lt;br&gt;
Ssorted = S(si) &lt;br&gt;
&lt;br&gt;
% did we arrive at the correct answer&lt;br&gt;
isequal(Ssorted,Srequired) % yes&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
hth&lt;br&gt;
Jos</description>
    </item>
  </channel>
</rss>

