MATLAB Classes - MATLAB & Simulink (original) (raw)
Main Content
Code generation for MATLAB® Classes
You can generate code for MATLAB classes, including value classes, handle classes, and System objects. In the generated C code, MATLAB classes are represented as structures. If you generate C++ code, the default behavior of the code generator is to produce C++ classes for the MATLAB classes. You must be aware of certain usage notes and limitations when using classes in your MATLAB code that is intended for code generation.
Classes
coder.ClassType | Represent set of MATLAB classes acceptable for input specification |
---|
Topics
Code Generation Basics
- Generate Code for MATLAB Value Classes
Use a value class in MATLAB code intended for code generation. - Generate Code for MATLAB Handle Classes and System Objects
Use your System object™ in MATLAB code intended for code generation. - Generate C++ Classes for MATLAB Classes
Generate a C++ class for a value class, handle class, or System object in your MATLAB code.
Input Specification
- Specify Objects as Inputs at the Command Line
Specify that an entry-point input is an object of a value class by using thecodegen
-args
option. - Specify Objects as Inputs in the MATLAB Coder App
Define the type of a value class input from a test file or an example input.
Usage Notes and Limitations
- MATLAB Classes Definition for Code Generation
Use classes in MATLAB code intended for code generation. - Classes That Support Code Generation
Generate code for MATLAB value and handle classes and user-defined System objects. - System Objects in MATLAB Code Generation
Special considerations for using System objects in code generated from MATLAB. - Code Generation for Handle Class Destructors
Use a handle class destructor in MATLAB code intended for code generation.
Troubleshooting
Handle Object Limitations for Code Generation
Adhere to code generation restrictions for handle objects.
Troubleshoot issues with assignment of a property of a handle class.
Passing By Reference Not Supported for Some Properties
You cannot use certain properties with coder.ref
,coder.rref
, or coder.wref
.
Resolve Error: Code Generator Failed to Produce C++ Destructor for MATLAB Class
Troubleshoot generation of standalone code for C++ destructor of a MATLAB class.
Work Around Language Limitation: Code Generation Does Not Support Object Arrays
Troubleshoot code generation failure for arrays of objects in your MATLAB code.
Featured Examples
Generate C++ Classes for MATLAB Classes That Model Simple and Damped Oscillators
See how object-oriented MATLAB code maps to generated C++ code and how to use the generated C++ code.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
Belgium (English)
Denmark (English)
Deutschland (Deutsch)
España (Español)
Finland (English)
France (Français)
Ireland (English)
Italia (Italiano)
Luxembourg (English)
Netherlands (English)
Norway (English)
Österreich (Deutsch)
Portugal (English)
Sweden (English)
Switzerland
United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)