如何设置代码生成时文件的编码

조회 수: 13 (최근 30일)
leifeng song
leifeng song 2025년 9월 22일 10:39
댓글: leifeng song 2025년 9월 28일 3:25
电脑的语言是中文,使用Simulink搭建的模型,生成代码时,代码文件的编码都为中文编码,我想设置文件编码为UTF8,应该如何设置。

답변 (1개)

Esther
Esther 2025년 9월 24일 1:55
You can specify the encoding used for generated code by using the slCharacterEncoding function in MATLAB.
For example, run the following command before code generation:
>> slCharacterEncoding('UTF-8');
After running this, the generated C and H files will be encoded in UTF-8.
Please note that this setting applies for the current MATLAB session.
  댓글 수: 1
leifeng song
leifeng song 2025년 9월 28일 3:25
Thank you,but it does not work. the function "slCharacterEncoding" was description in slCharacterEncoding - 指定要在从 Simulink 模型生成的代码中使用的编码 - MATLAB.
I try it,the result is ,once there is some chinese comment words in the generator code , the code file encoding turns GB2312,otherwise ,the encoding is UTF-8.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 建模에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!