matlab中文显示乱码:控制台上的,编辑器的,图片中的
2018-01-11 17:27
513 查看
问题:matlab脚本与函数文件的中文注释显示乱码.
环境:matlab R2016a.Windows 10 home.
解决方案:
step1
检查locale值
matlab命令行键入命令
feature(‘locale’)
注意:
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.
环境: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.
相关文章推荐
- matlab 图片显示出现中文乱码
- ubuntu 安装Matlab 解决显示中文乱码
- Java 控制台输入中文时,显示结果是乱码!
- PHP Fckeditor上传文件(或图片)中文显示为乱码的解决方法
- Ubuntu中Atom编辑器显示中文乱码的处理方法
- Google appengine中文乱码问题 和图片显示问题
- ubuntu 安装Matlab 解决显示中文乱码
- Ubuntu/Debian下JAVA 中文/图片中文字体乱码显示问题解决方法
- Linux技巧--Redhat 5系统中的vim编辑器无法正常显示中文解决方案(中文显示为乱码)/Ubuntu 12.04系统gedit中文乱码
- eclipse下启动weblogic控制台显示中文乱码问题
- 解决windows系统 android 控制台调试显示中文乱码
- VS2017控制台程序显示中文为乱码的问题解决办法
- linux环境通过ssh连接控制台显示中文乱码问题
- linux环境通过ssh连接控制台显示中文乱码问题
- matplotlib中画图显示中文,但保存为图片后中文乱码
- IDea 12 编辑器 中文显示乱码问题 解决
- flash builder控制台显示中文乱码问题解决方法
- Ubuntu下CodeBlocks控制台程序中文显示乱码解决问题
- 安装了中文的linux,使得linux黑白控制台显示英文而是不乱码