MATLAB Answers

How do I get my MATLAB editor to read UTF-8 characters? UTF-8 characters in blank squares in editors, but in the command window and workspace works fine.

753 views (last 30 days)
Yohahn Jo
Yohahn Jo on 26 Apr 2016
Commented: Walter Roberson on 6 Nov 2020
I have a project, which is commented in UTF-8 characters.
I tried changing the system locale on my Windows 10, however MATLAB editor is not recognizing UTF-8 characters(in blank squares). I'm not sure what to do here.
If I open the same .m file in text editor, it works fine.
How do I get my MATLAB editor to read UTF-8? Thank you
ans =
ans =
ctype: ''
collate: ''
time: ''
numeric: ''
monetary: ''
messages: ''
encoding: 'windows-1252'
terminalEncoding: 'windows-949'
jvmEncoding: 'Cp1252'
status: 'MathWorks locale management system initialized.'
warning: 'System locale setting, ko_KR, is different from user locale setti…'
Keith Hooks
Keith Hooks on 30 Aug 2016
I'm having the same problem. It seems that editing the lcdata.xml file to change the encoding of en_US has no effect at all. It stays windows-1252 no matter what I change it to in the file.

Sign in to comment.

Accepted Answer

Jinghao Lei
Jinghao Lei on 20 Oct 2016
I have a very tricky way to solve this problem. And it seems works. In my case, (windows matlab 2016b x64)
always output below even I have modified lcdata.xml
ctype: 'zh_CN.GBK'
so, I delete this in lcdata.xml (in codeset)
<encoding name="GBK">
<encoding_alias name="936">
then I change following
<encoding name="UTF-8">
<encoding_alias name="utf8"/>
<encoding name="UTF-8">
<encoding_alias name="utf8"/>
<encoding_alias name="GBK"/>
The point is cheat matlab GBK is just alias of utf8

Sign in to comment.

More Answers (1)

Michael Cappello
Michael Cappello on 31 Oct 2017
% read in the file fID = fopen(filename, 'r', 'n', 'UTF-8'); bytes = fread(fID); fclose(fID);
% The data read from the file can then be converted into Unicode characters, like so: unic = native2unicode(bytes, 'UTF-8');
% if you want, clear the Carriage Returns, set the Line Feeds to a space unic(unic == 10) = []; unic(unic == 13) = ' ';
disp(unic'); % display the Unicode text

Community Treasure Hunt

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

Start Hunting!

Translated by