• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

问题:matlab脚本与函数文件的中文注释显示乱码. 
环境:matlab R2016a.Windows 10 home. 
解决方案: 
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: \'\'

 

 

 

注意: 
System locale设置 
控制面板Region,Administrative选项卡,Language for non-Unicode设置为Chinese(Simplified,China). 
step3 
确认效果. 
打开m文件,添加中文注释,保存并重新打开确认中文显示正常. 
注意: 
如果中文字符显示?是乱码问题,如果显示方框则是字体显示问题(比如使用西方字体显示中文字体).可在matlab预设->字体选择中文字体.matlab默认设置为Monospaced,如果系统没有支持等宽字体的中文字体,中文字符会显示方框.可以下载并安装宋体-18030,该字体支持等宽字体. 
补充 
如果想以utf-8编码,而不是GBK编码的话,请编辑matlab的locale数据库文件lcdata.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编码. 
注意: 
常见的编码格式 
• ascII编码,别名ANSI,使用7个bit. 
• utf-8,可变长度,兼容ascII,中文字符占16个bit 
• utf-16,左右字符一律占16个bit 
• GB2312,简体中文 
• GB5,繁体中文 
lcdata.xml修改locale tag不起作用,我猜测matlab硬编码了locale列表,而不是查询lcdata.xml.其内部的locale格式 
locale — Format: language_territory.codeset 
For example, for the U.S. English locale setting en_US.US-ASCII, en means that the display language is English. US indicates that time and date displays use U.S. conventions. US-ASCII is the coded character set (codeset) used to display text.

From https://www.mathworks.com/help/matlab/matlab_env/how-the-matlab-process-uses-locale-settings.html 
如果你的系统和用户locale值均为zh_CN,则matlab查询硬编码存储的locale列表定位到zh_CN.GBK,并使用GBK在lcdata.xml查询codeset.

参考文献 
• ISO-3166 Country Codes 
• ISO-639 Language Codes 
• Internationalization(matlab帮助) 
• 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.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
关于delphi编译路径设置问题发布时间:2022-07-18
下一篇:
调用关机对话框delphi发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap