MATLAB: Can I use MATLAB classes in Simulink

simulink

We are trying to define some classes in separate .m files. Then we are using a instance for one of the classes in Simulink MATLAB function block to execute one of the methods of this class but we are having problems to launch it in Simulink.
We would like to know how we can use classes written in MATLAB in Simulink with the final goal of generating code.

Best Answer

You can use MATLAB classes in Simulink for code generation through MATLAB Function block.
For best practices when creating MATLAB classes for code generation:
Not all MATLAB functions are supported for code generation. Refer to this page for a list of supported functions:
In addition, this page discusses best practices for defining variables for code generation:
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: