필터 지우기
필터 지우기

How to assign a Russian string to a variable

조회 수: 3 (최근 30일)
Kotya Karapetyan
Kotya Karapetyan 2011년 12월 20일
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!

답변 (1개)

Walter Roberson
Walter Roberson 2011년 12월 20일
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
Kotya Karapetyan
Kotya Karapetyan 2011년 12월 21일
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 2012년 1월 3일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by