unicode characters in .m file

134 Ansichten (letzte 30 Tage)
Paul McKenzie
Paul McKenzie am 18 Mai 2017
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(°).
  2 Kommentare
Paul McKenzie
Paul McKenzie am 19 Jul. 2017
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.
Walter Roberson
Walter Roberson am 19 Jul. 2017
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Rahul Arora
Rahul Arora am 17 Jul. 2017
Bearbeitet: Rahul Arora am 17 Jul. 2017
For R2017a, the steps are similar to the ones described in https://www.mathworks.com/matlabcentral/answers/280988-how-do-i-get-my-matlab-editor-to-read-utf-8-characters-utf-8-characters-in-blank-squares-in-editors. 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.
<codeset>
<encoding name="UTF-8">
<encoding_alias name="windows-1252" />
</encoding>
</codeset>
Just modify based on your own system encoding.
  4 Kommentare
Andrey Kazak
Andrey Kazak am 13 Mai 2019
The fix does not work on 2018b for Windows.
Please suggest a workaround.
Thank you.
Rahul Arora
Rahul Arora am 28 Nov. 2019
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (5)

MathWorks Support Team
MathWorks Support Team am 19 Feb. 2021
Bearbeitet: MathWorks Support Team am 19 Feb. 2021
As of R2020a, the MATLAB Editor supports UTF-8 characters, and uses UTF-8 as the default encoding for new plain text files, including MATLAB code files with a .m extension.

Walter Roberson
Walter Roberson am 19 Mai 2017
  1 Kommentar
Stephane
Stephane am 9 Nov. 2018
This one worked for me (MacOS Mojave, R2018b) - Thanks !

Melden Sie sich an, um zu kommentieren.


Jan
Jan am 19 Mai 2017
  14 Kommentare
Paul McKenzie
Paul McKenzie am 3 Apr. 2020
R2020a is out and solves the problem! All .m files are saved in UTF-8 format.
Shaul Shvimmer
Shaul Shvimmer am 31 Jul. 2020
I'm using MATLAB 2020a and I still have the problem - I cannot change encoding to UTF-8 using Windows 10.

Melden Sie sich an, um zu kommentieren.


Muhammad  Kashif
Muhammad Kashif am 14 Mär. 2018
Bearbeitet: Muhammad Kashif am 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:
>>slCharacterEncoding('UTF-8')
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 Kommentar
Walter Roberson
Walter Roberson am 14 Sep. 2019
Unfortunately, slCharacterEncoding() is for Simulink use, not the MATLAB command prompt.

Melden Sie sich an, um zu kommentieren.


Jean-Michel Rousseau
Jean-Michel Rousseau am 10 Jan. 2020
Hello,
Is ther any way to definitively change the 'DefaultCharacterSet' without the need to use the feature function at every start of Matlab?
I need to use 'windows-1252' and Matlab (& Simulink) always start with "UTF-8". It as recently canged after updating to the R2019b. As I can't solve the problem into R2019b (my folders and files with accent can't be used anymore without renaming them), i go back to a fresh R2016b but the problem remain :-(

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by