Unicode characters in MATLAB source files

后端 未结 5 1537
执笔经年
执笔经年 2020-11-30 05:55

I\'d like to use Unicode characters in comments in a MATLAB source file. This seems to work when I write the text; however, if I close the file and reload it, \"unusual\" ch

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 06:28

    Mac OSX only!

    As I found solution which worked in my case I want to share it.

    Mathworks advises here to use slCharacterEncoding(encoding) in order to change the encoding as desired, but for the OSX this does not solve the issue exactly as the feature('DefaultCharacterSet') in accepted answer does not do it. What helped me to get the UTF-8 encoding set for opening and saving .m files was the following link on MATLAB answers: https://www.mathworks.com/matlabcentral/answers/12422-macosx-encoding-problem

    Matlab seems to ignore any value set in slCharacterEncoding(encoding) or feature('DefaultCharacterSet') but uses region set in System Preferences -> Language & Region. After checking which region is selected in our case then it is possible to define the actual encoding in the hidden configuration file in

     $matlabroot/bin/lcdata.xml
    

    This directory can be opened by getting to the Applications and after right click on Matlab by selecting Show Package Contents as on screenshot (here in German)

    For example for German default ISO-8859-1 it is possible to adjust it by changing the respective line in the file lcdata.xml:

     
    

    to:

     
    

    If the region which is selected is not present in the lcdata.xml file this will not work.

    Hope this helps!

提交回复
热议问题