MATLAB Answers


unicode characters in .m file

Asked by Paul McKenzie on 18 May 2017
Latest activity Commented on by Rahul Arora on 28 Nov 2019 at 19:05
Matlab claims to be Unicode compliant, but only characters whose code # is ≤255 can be saved in .m files. I can accept that Matlab code words must be in ASCII, but there should be no such constraints on characters in comments or text strings. It would be nice if useful characters, like "≈", "Ω", "≤","≥", etc., could be saved in comments. On a similar note, while a character whose code is ≥128 and ≤255 can be stored in .m files, it is not possible to include them directly in graphics labels or text; typing '\circ' (1970s LaTex convention) seems clunky compared to "Alt+0176" (or pasted from another document) for the degrees symbol(°).


While there now seem to be solutions for storing Unicode characters in .m files, I would still like a better alternative to the clunky LaTex method for special characters on plots. With the advent of Unicode, I don't see why labels, titles, and texts shouldn't be specified directly in Unicode. That would make the .m file text look like the text on the plot. (I think they call that approach 'WYSIWYG'.) Adding an 'Insert Symbol' feature to the editor would make labels, titles, and texts so much more convenient then remembering arcane \<symbol> sequences.
unicode characters can be included directly for text() objects when using Interpreter Tex (the default) or Interpreter None . However, at this time unicode characters cannot be included directly for latex.

Sign in to comment.

4 Answers

Answer by Rahul Arora on 17 Jul 2017
Edited by Rahul Arora on 17 Jul 2017
 Accepted Answer

For R2017a, the steps are similar to the ones described in The only difference is that the matlabroot/bin/lcdata.xml file no longer describes all standard locales and encodings. But you can still use this file for customizing the locale database.
For my case, the encoding is windows-1252 (you can find your encoding using the feature('locale') command), and therefore, I added the following lines to the <lcdata> ... </lcdata> block in lcdata.xml.
<encoding name="UTF-8">
<encoding_alias name="windows-1252" />
Just modify based on your own system encoding.


Show 1 older comment
being a bit late here: can I change this property for each user? Unfortunately I do not have access to lcdata.xml, I am not admin on my machine... Also lcdata.xml does not have any
entries on my machine, just a few commented lines
The fix does not work on 2018b for Windows.
Please suggest a workaround.
Thank you.
Rahul Arora on 28 Nov 2019 at 19:05
Hi Andrey
I just tried doing this on my MATLAB installation (R2019b, Windows 10) and it works fine. Please note that you have to restart MATLAB after performing the edit I suggested.

Sign in to comment.

Answer by Walter Roberson
on 19 May 2017

  1 Comment

Stephane on 9 Nov 2018
This one worked for me (MacOS Mojave, R2018b) - Thanks !

Sign in to comment.

Answer by Jan
on 19 May 2017


Mathworks needs to do more to make it easy to use Unicode in source code, UTF-8 at least.
R2019a is out, but the editor still cannot handle Unicode!
Note to Mathworks Editor Design Team: Check out the comprehensive and elegant way Octave allows one to select text encoding.
Now R2019b is out, and the editor still cannot handle unicode. Since that's the case, why does Matlab still include the file "lcdata_utf8.xml", since it no longer provides any unicode capability?

Sign in to comment.

Answer by Muhammad Kashif on 14 Mar 2018
Edited by Muhammad Kashif on 6 Apr 2018

Assalam O Alikum and good day all
For those using languages having Arabic script e.g. Arabic ,Urdu.
1)Change the system Locale to Urdu(Pakistan) for Urdu.For Arabic, change the system locale accordingly.
2)For displaying Urdu and Arabic in Matlab Command prompt,use the following command:
3) In the matlab editor, to make the string functions like strsplit() work properly for Urdu and Arabic, this should be the first line of code:
feature('DefaultCharacterSet', 'UTF8');
Best regards

  1 Comment

Unfortunately, slCharacterEncoding() is for Simulink use, not the MATLAB command prompt.

Sign in to comment.