How to display Chinese character in gui table / command window
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Hello, I want to display Chinese character in gui table or command window, how to do that? Such as I want "单位" displayed in command window, I use
str = '单位'
then I got this
str =
位
When I read EXCEL by GUI table, it is same. What can I do? And I do not want to change any property or setting with my environment. So is there some code I can use like
str = ['<html> strtype="UTF-8", str='单位'<html>'] %dummy code
PS: I use a Japanese Windows system, and Chinese character could correctly displayed in text/folder name/excel and so on.
Sorry for my English.
Thanks.
채택된 답변
Robert U
2017년 8월 29일
Hello kei hin,
there is one possibility to display chinese characters by switching the default character set to UTF-8 as described here: https://de.mathworks.com/matlabcentral/answers/116527-how-to-display-chinese-character-in-edit-text-box-in-matlab-gui
or try the following function, that worked on my machine (commented lines are for try in case the code does not work on your machine properly):
function drawTable(Data)
% %%Change default character set
% defCharSet = feature('DefaultCharacterSet', 'UTF8');
% %%Add html tag to Data
% Data(:) = strcat('<html><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />', ...
% Data(:));
%%Plot figure and uitable
f = figure;
t = uitable(f,'ColumnFormat',[],'Data',Data,'ColumnWidth',{50});
% %%Restore default char set
% feature('DefaultCharacterSet', defCharSet);
end

Kind regards,
Robert
댓글 수: 7
Thanks a lot. I tried your code without commented lines. It didn't work. I think commented lines will change my Matlab setting, so I won't try it.
By the way, how can I know what is my default character set? I can't find anything about 'feature()' or 'DefaultCharacterSet' in my matlab help(F1).
Thank you so much.
Calling
feature('DefaultCharacterSet')
shows your default character set.
The feature()-function is undocumented. You can find a similar question with answer by Walter Roberson using the "Search Answers"-Feature on this website (see web-link in my answer).
Kind regards,
Robert
PS: The standard character set on my machine is 'windows-1252'. Yours might be different.
I tried
feature('DefaultCharacterSet')
then I got
ans =
Shift_JIS
so In your first answer
%%Change default character set
defCharSet = feature('DefaultCharacterSet', 'UTF8');
I guess that will change my default character set to 'UTF8'. But what will the 'defCharSet' get? If 'defCharSet' get 'UTF8', your code
%%Restore default char set
feature('DefaultCharacterSet', defCharSet);
I think it is not OK when you restore default char set by 'defCharSet' you got before.
So, should I have to save my default character set to a tmp? Like this
tmp = feature('DefaultCharacterSet'); % get default character set to 'tmp', it will be 'Shift_JIS'
newCharSet = feature('DefaultCharacterSet', 'UTF8'); % change to 'UTF8'
% do something
feature('DefaultCharacterSet', tmp); % use 'tmp' to restore default char set to 'Shift_JIS'
Am I right?
Hello kei hin,
the function call
%%Change default character set
defCharSet = feature('DefaultCharacterSet', 'UTF8');
sets your actual character set to UTF-8 and returns the previously set character set, saving it in the variable "defCharSet".
The function head can be read from Matlab path "YourMatlabRootFolder"\toolbox\distcomp\@distcomp\feature.m as
function oldValue = feature( name, optValue )
;%#ok<NOSEM> undocumented
in version R2014b.
Thus, restoring the previously set character set can be done by calling
feature('DefaultCharacterSet', defCharSet);
No return variable is needed, since you know the character set you are changing back from.
Kind regards,
Robert
Hello Robert, thank you so much. I tried to change and restore character set, it is OK. But even though I use 'UTF8' or 'GB2312', '单位' is also can't displayed correctly. I tried your first answer with commented lines too. My version is R2011b. and feature() is a P-file. Any idea?
Are you using the above solution as script-code or as function (as presented above)?
First, as script it did not work at any time. Calling the function surprisingly did work.
Check whether your variable is stored correctly:
% write 单 into a variable
TestVar = char('单');
dec2hex(double(TestVar))
Check in workspace whether TestVar contains the correct character or a replacement character. If there is a replacement character try the next 'DefaultCharacterSet'.
% compare hexadecimal representation of '单' in actual encoding
dec2hex(double('单'))
char(hex2dec('5355'))
Kind regards,
Robert
A variable assigned inside the function is not stored correctly but by the replacement character '3F'. Strangely, throwing the function input directly to uitable does not cause any problem.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Tables에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
