Matlab如何以UTF-8編碼保存?
有時候程序中的注釋是用中文寫的,在這種情況下Matlab就會使用GB-2312編碼保存腳本,然而像bitbucket這種代碼託管網站並不能識別GB-2312編碼……
有沒有什麼辦法另Matlab所有的腳本都保存為UTF-8編碼呢?P.S. 我現在是用notepad++ 打開m文件然後轉換為UTF-8編碼,不過每次都這樣操作有點繁瑣……
我在 Vim 下寫代碼,以確保所有源文件都是 Unix/UTF-8 格式。調試在 Matlab 下完成。反正 Matlab 的編輯器本來就很弱……
找到 MATLAB 的根目錄
找到 lcdata.xml 文件,打開
如果你的系統是中文的,就找到這麼一行
把 encoding="XXx" 改為你想要的編碼
保存
重啟 MATLAB
2016.12.4 更新
for Mac 用戶
系統更新到 Sierra 後,MATLAB 就找不到自己的配置路徑了,所以所有編碼自動轉為 ASCII,
來MathWorks Account下個補丁就好了( ̄▽ ̄)"
有用就點個贊嘛o(* ̄3 ̄)o
如果遇到這類問題搜索不到答案可以嘗試用英文搜一下,可能會有你想要的答案。
slCharacterEncoding
Change MATLAB character set encoding
collapse all in page
Syntax
currentCharacterEncoding = slCharacterEncoding()
slCharacterEncoding(encoding)
Description
This command allows you to change the current MATLAB? character set encoding to be compatible with the character encoding of a model that you want to open.
currentCharacterEncoding = slCharacterEncoding() returns the current MATLAB character set encoding.
slCharacterEncoding(encoding) changes the MATLAB character set encoding to the specified encoding. You should only specify these values:
- "US-ASCII"
- "Windows-1252"
- "ISO-8859-1"
- "Shift_JIS"
- "UTF-8"
If you want to use a different character encoding, you need to start MATLAB with the appropriate locale settings for your operating system. Consult your operating system manual to change the locale setting. Simulink? can support any character encoding that uses single-byte or double-byte characters.
If you open a model that uses a particular character set encoding in a MATLAB session that uses a different encoding, a warning appears. For example, suppose that you create a model in a MATLAB session configured for Shift_JIS and open it in a session configured for US_ASCII. The warning message shows the encoding of the current session and the encoding used to create the model. If you encounter any problems with corrupted characters, for example when using MATLAB files associated with the model, then try using the slCharacterEncoding function to change the character encoding
- Close all open models.
- Use slCharacterEncoding to change the character encoding of the current MATLAB session to match the model character encoding.
- Reopen the model.
Note You must close all open models or libraries before changing the MATLAB character set encoding except when changing from "US-ASCII" to another encoding.
來自 &
綜上
slCharacterEncoding("UTF-8")
如果你想使用另一種字元編碼,你需要修改操作系統的本地設置。
在命令窗口輸入命令:
feature("locale")
可以看到多是用 GBK 進行編碼。
如果想以 utf-8 編碼,而不是 GBK 編碼的話,請編輯 matlab 的 locale 資料庫文件 lcdata.xml (matlab bin 目錄下).
刪除
&
&< encoding_alias name=」936」&>
&
並將
&
&
&
改為
&
&
&
&
重啟 matlab 之後,即以 utf-8 編碼.
版本 2016b
解決matlab中文亂碼 - 編程語言 - IT問道
有幫助
推薦閱讀:
※matlab 函數返回值列表太長,覺得醜陋,怎麼辦?
※Mathematica 為什麼沒有像matlab一樣的clear 和clc功能?
※如何優雅地使用gams、matlab、AIMMS、LINGO?
TAG:Unicode統一碼 | MATLAB | 字元編碼 | UTF-8 |