matlab程序窗口是乱码,解决matlab中文乱码

问题:matlab脚本与函数文件的中文注释显示乱码.

环境:matlab R2016a.Windows 10 home.

解决方案:

step1

检查locale值

matlab命令行键入命令

feature(‘locale’)

显示

0818b9ca8b590ca3270a3433284dd417.png

发现问题,System locale与User locale设置不一样,System locale设置了zh_CN,而User locale设置了en_US.

注意:

locale格式为 LanguageCode_CountryCode.相应的定义Language code请见ISO-639,而Country code请见ISO-3166

step2

将User locale设置为zh_CN.

控制面板Region,Formats选项卡,Format设置为Chinese(Simplified,China).

再次确认locale值(重启matlab使之生效),此时显示

0818b9ca8b590ca3270a3433284dd417.png

注意:

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.

参考文献 • 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值