Matlab text comments are garbled (GBK and UTF8 interchangeable)

There are two encoding formats in the high version of MATLAB (2017a and above)

GBK and UTF-8. After the encoding format is modified, the problem of garbled characters in the existing m files may be solved, but the problem of garbled characters in the original comments.
The default encoding of matlab is GBK, and GBK files can be opened directly without Chinese garbled characters.
When using matlab to open the .m file encoded with UTF-8, there will be a problem of Chinese garbled characters.
Find the encoding format
Open matlab and enter in the command serial port:slCharacterEncoding()

Solution

Change the matlab default encoding to UTF-8.
My matlab version is 2018b, and the default GBK. I won’t talk about many methods on the Internet. The best way is to change the encoding method and do it in one step.

  1. Open the matlab installation path, find the bin file, the lcdata_utf8.xml file below
    insert image description here
  2. Open the lcdata_utf8.xml file with Notepad and save it as lcdata.xml file. If the lcdata.xml file already exists in the bin directory, first rename the original lcdata.xml file (as shown in the lcdata2.xml file above), and then save it as lcdata. xml file.
  3. Open the lcdata.xml file with Notepad, modify it (ctrl+f search shortcut), find the following code and delete it
        <encoding name="GBK">
            <encoding_alias name="936"/>
        </encoding>
  1. keep looking, find
        <encoding name="UTF-8">
            <encoding_alias name="utf8"/>
        </encoding>

change into

        <encoding name="UTF-8">
            <encoding_alias name="utf8"/>
            <encoding_alias name="GBK"/>
        </encoding>
  1. Save the modification, restart matlab, no garbled characters, success!
    insert image description here
    The reverse operation of converting utf8 to GBK
    is the same idea is to delete part of the code, and add <encoding_alias name="utf8"/> to that part.

Guess you like

Origin blog.csdn.net/weixin_45080292/article/details/125356133