How to assign a Russian string to a variable

2 views (last 30 days)
When I am doing something like
'a'-0
I get the ASCII code of the character, 97 in this example. However for Russian letters I always get 26. How can I make Matlab accept Russian letters?
Eventually I need it to accept Russian strings obtained with
urlread
Thanks!

Answers (1)

Walter Roberson
Walter Roberson on 20 Dec 2011
When you read from a web page, you should get back a header that looks similar to
Content-Type: text/html; charset=utf-8
If charset is utf-8 then the implication is that all possible Unicode characters could be returned, and that the byte values used will correspond to the Unicode standards. You would process this by using native2unicode or unicode2native .
If, though, charset is koi8-r or iso-8859-5 then you will need to do character translation. The translation table for koi8-r is shown at http://en.wikipedia.org/wiki/KOI8-R . The middle value for each cell of the table is the Unicode code point for the character, expressed (as is traditional) as four hex digits. For example, there Д shows 0414 hex, which is decimal 1044, and char(1044) in the command window does show Д if you are using the default character set for MATLAB (but people who have their computer set to languages other than English might be set up for other character sets.)
  2 Comments
Kotya Karapetyan
Kotya Karapetyan on 21 Dec 2011
Aha, this is already something.
a = char(1044);
a-0
returns 1044 and not 26.
However I still do not see the letters. I'd like to see them.
I think my computer is set to English. I'm using Win 7. Control Panel > Region and Language > Format is United Kingdom, Location is also United Kingdom. "Current language for non-Unicode programs" is "English (United Kingdom)".
How can I check what is the character set Matlab is using? Can I change it within Matlab?
Walter Roberson
Walter Roberson on 3 Jan 2012
Please see http://www.mathworks.com/matlabcentral/answers/9738-problem-opening-files-containing-special-characters for an example of checking it. I do not know if it can be changed within MATLAB.

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!