matlab中文显示乱码:控制台上的,编辑器的,图片中的

这个方法有很多后遗症,建议放弃:

问题:matlab脚本与函数文件的中文注释显示乱码.
环境:matlab R2019a. Windows 10
参考:
[1] https://www.cnblogs.com/leoking01/p/8269516.html
[2] 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

注意:方法[1]不适合matlab 2017a及以后版本

解决方案:
step1
检查locale值
matlab命令行键入命令
feature(‘locale’)

复制代码

feature('locale')
ans =
包含以下字段的 struct:

           ctype: 'zh_CN.UTF-8'
         collate: 'zh_CN.UTF-8'
            time: 'zh_CN.UTF-8'
         numeric: 'en_US_POSIX.UTF-8'
        monetary: 'zh_CN.UTF-8'
        messages: 'zh_CN.UTF-8'
        encoding: 'UTF-8'
terminalEncoding: 'UTF-8'
     jvmEncoding: 'UTF-8'
          status: 'MathWorks locale management system initialized.'
         warning: ''

step2
System locale设置
控制面板Region,Administrative选项卡,Language for non-Unicode设置为Chinese(Simplified,China).

step3
确认效果.
打开m文件,添加中文注释,保存并重新打开确认中文显示正常.
注意:
如果中文字符显示?是乱码问题,如果显示方框则是字体显示问题(比如使用西方字体显示中文字体).可在matlab预设->字体选择中文字体.matlab默认设置为Monospaced,如果系统没有支持等宽字体的中文字体,中文字符会显示方框.可以下载并安装宋体-18030,该字体支持等宽字体.
补充
如果想以utf-8编码,而不是GBK编码的话,请编辑matlab的locale数据库文件lcdata_utf8.xml(matlab bin目录下).
删除
< encoding name=”GBK”>
< encoding_alias name=”936”>
< /encoding>

并将
< encoding name=”UTF-8”>
< encoding_alias name=”utf8”/>
< /encoding>
改为< encoding name=”UTF-8”>
< encoding_alias name=”utf8”/>
< encoding_alias name=”GBK”/>
< /encoding>
重启matlab之后,即以utf-8编码.

step4

For MATLAB2017a users, as noticed there is empty in lcdata.xml except some comments. So we should first rename the lcdata_utf8.xml to lcdata.xml,

把lcdata_utf8.xml,另存为lcdata.xml,覆盖掉原先的lcdata.xml

posted @ 2020-07-12 12:25  ChrainY  阅读(870)  评论(0编辑  收藏  举报