Can I use MATLAB classes in Simulink?

조회 수: 100 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2018년 7월 10일
댓글: Walter Roberson 2023년 2월 6일
I am trying to define a class in a MATLAB ('.m') file. Then, I am using an instance of one of that class in a Simulink "MATLAB function" block to execute one of the methods of the class. However, I am having trouble launching it in Simulink. 
How can I use classes written in MATLAB in Simulink? Ultimately, I would like to generate code from my model.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2023년 2월 6일
편집: MathWorks Support Team 2023년 2월 6일
You can use MATLAB classes in Simulink for code generation through MATLAB Function block.
Not all MATLAB functions are supported for code generation. Refer to this page for a list of supported functions: https://www.mathworks.com/help/simulink/ug/functions-and-objects-supported-for-cc-code-generation.html
In addition, this page discusses best practices for defining variables for code generation: https://www.mathworks.com/help/releases/R2022b/simulink/ug/best-practices-for-defining-variables-for-c-c-code-generation.html
The MATLAB Function documentation page include links to various examples and useful articles that explains the limitations and best practices for writing MATLAB code for code generation:
These example uses MATLAB system object class in Simulink:
  댓글 수: 2
Walter Roberson
Walter Roberson 2023년 1월 30일
https://www.mathworks.com/help/simulink/slref/matlabfunction.html
https://www.mathworks.com/help/simulink/ug/define-system-object-for-use-in-simulink.html
Walter Roberson
Walter Roberson 2023년 2월 6일
URL-hacking of the help information does not always work, but it is a good first step.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by