Can I use MATLAB classes in Simulink?
100 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 10 Jul. 2018
Kommentiert: Walter Roberson
am 6 Feb. 2023
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.
Akzeptierte Antwort
MathWorks Support Team
am 6 Feb. 2023
Bearbeitet: MathWorks Support Team
am 6 Feb. 2023
You can use MATLAB classes in Simulink for code generation through MATLAB Function block.
For best practices when creating MATLAB classes for code generation: https://www.mathworks.com/help/releases/R2022b/simulink/ug/how-working-with-matlab-classes-is-different-for-code-generation.html
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 Kommentare
Walter Roberson
am 30 Jan. 2023
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
am 6 Feb. 2023
URL-hacking of the help information does not always work, but it is a good first step.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulink Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!