Algorithm Design Basics
Generating code from MATLAB® algorithms allows you to design, implement, and test software completely within the MATLAB workspace. You can:
Verify that your algorithms are suitable for code generation
Generate efficient, readable, and compact C/C++ code automatically, eliminating manually translation and minimizing the risk of introducing errors in the code.
Modify your design in MATLAB code to take into account the specific requirements of desktop and embedded applications, such as data type management, memory use, and speed.
Test the generated code and easily verify that your modified algorithms are functionally equivalent to your original MATLAB algorithms.
Generate MEX functions to accelerate MATLAB algorithms or speed up fixed-point MATLAB code.
Generate hardware description language (HDL) from MATLAB code.
To generate C/C++ or MEX code from MATLAB algorithms, you must have MATLAB Coder™ and a C/C++ compiler installed.
Functions
coder.allowpcode | Control code generation from P-code files |
coder.ceval | Call C/C++ function from generated code |
coder.cinclude | Include header file in generated code |
coder.cstructname | Name generated or externally defined structure type in C or C++ code |
coder.extrinsic | Declare function as extrinsic and execute it in MATLAB |
coder.inline | Control inlining of current function in generated code |
coder.inlineCall | Inline called function in generated code (Since R2024a) |
coder.load | Load constants from MAT file or ASCII file at code generation time |
coder.nonInlineCall | Prevent inlining of called function in generated code (Since R2024a) |
coder.nullcopy | Declare uninitialized variables in generated code |
coder.opaque | Declare variable in generated code |
coder.ref | Indicate data to pass by reference |
coder.rref | Indicate read-only data to pass by reference |
coder.target | Determine if code generation target is specified target |
coder.unroll | Unroll for-loop by making a copy of
the loop body for each loop iteration |
coder.varsize | Resolve size incompatibility errors and declare upper bounds |
coder.wref | Indicate write-only data to pass by reference |
coder.updateBuildInfo | Update RTW.BuildInfo build information object |
Classes
coder.ExternalDependency | Interface to external code |
coder.BuildConfig | Build context during code generation |
Topics
- When to Generate Code from MATLAB Algorithms
Decide whether to generate code for your application.
- Which Code Generation Feature to Use
Choose code generation feature for your application.
- Differences Between Generated Code and MATLAB Code
Generated C/C++ code can behave differently than original MATLAB source code.
- MATLAB Language Features Supported for C/C++ Code Generation
Use the MATLAB language features and functions that code generation supports.
- MATLAB Code Design Considerations for Code Generation
When writing MATLAB for code generation, consider design constraints.
Troubleshooting
Resolve Error: Unknown Output Type for coder.ceval
Troubleshoot error when the code generator is unable to determine the output type of an external C/C++ function call.