MATLAB-Coder
Autor: | Prof. Dr.-Ing. Schneider |
Code Generation Requirements
The three most common code generation issues are solved with these preparation steps:
- Define function input variables.
- Preallocate arrays before indexing.
- Verify MATLAB Coder support.
To see what functions are supported for code generation, you can filter by C/C++ code generation in the documentation. Use the navigation on the left to find supported functions for different toolboxes.
MEX Functions
There are two main reasons you might want a MEX function. You can use MEX functions:
- in a test script to verify the generated code
- to accelerate your MATLAB algorithms
The acceleration workflow is very similar to the C/C++ source code generation workflow.
Variable Size Inputs
When generating C code from MATLAB functions, you need to specify the size, type, and complexity of the function inputs. For more adaptable functions, you can create type variables, balancing between flexibility and performance.
- Fixed size inputs only accept one input type but have the best performance.
- Unbounded dimensions offer maximum flexibility but lower performance.
- Defining an upper limit for array dimensions improves efficiency.
Configure Generated Code
You can configure how your C code is generated, including changes for readability, memory allocation, and execution speed. MATLAB Coder provides settings to prioritize based on your specific needs, such as optimizing runtime performance at the expense of code readability.
Next Steps
Completing the C and C++ code generation workflow opens various paths for using the generated code:
- Accelerate MATLAB algorithms with MEX functions.
- Create a standalone executable using a main function.
- Integrate into an existing C project using the raw source code or a library.
- Run your code on embedded microprocessors by compiling with your target processor's toolchain.
See Deploy Generated Code in the documentation for more information on these applications.
Related toolboxes:
- MATLAB Coder: Generate C and C++ code from MATLAB functions
- MATLAB Compiler: Build standalone executables and web apps from MATLAB programs
- Simulink Coder: Generate C and C++ code from Simulink and Stateflow models
- Embedded Coder: Generate C and C++ code optimized for embedded systems
Nützliche Artikel
- Generate C/C++ Code from a MATLAB Function
- Unit Test External C Code with MATLAB Coder
- Unit Testing C Code Using MATLAB and MATLAB Coder
- Generate Code for Sobel Edge Detection That Uses Half-Precision Data Type
- MATLAB to C/C++ Made Easy
- MATLAB Coder Onramp - Self-Paced Online Courses
- Integrating MATLAB and C/C++, Part 1
- Visualizing and Testing C/C++ Code | Integrating MATLAB and C/C++, Part 2