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