![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178002/image.png)
How to display Chinese character in gui table / command window
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178002/image.png)
Kind regards,
Robert
댓글 수: 7
Robert U
2017년 9월 7일
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
Robert U
2017년 9월 7일
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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!