MATLAB-Coder: Unterschied zwischen den Versionen
(9 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 5: | Zeile 5: | ||
| '''Autor:''' || [[Benutzer:Ulrich_Schneider| Prof. Dr.-Ing. Schneider]] | | '''Autor:''' || [[Benutzer:Ulrich_Schneider| 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 [https://www.mathworks.com/help/referencelist.html?type=function&capability=codegen 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 [https://www.mathworks.com/help/coder/ug/deploy-generated-code.html Deploy Generated Code] in the documentation for more information on these applications. | |||
Related toolboxes: | |||
* [https://www.mathworks.com/products/matlab-coder.html MATLAB Coder]: Generate C and C++ code from MATLAB functions | |||
* [https://www.mathworks.com/products/compiler.html MATLAB Compiler]: Build standalone executables and web apps from MATLAB programs | |||
* [https://www.mathworks.com/products/simulink-coder.html Simulink Coder]: Generate C and C++ code from Simulink and Stateflow models | |||
* [https://www.mathworks.com/products/embedded-coder.html Embedded Coder]: Generate C and C++ code optimized for embedded systems | |||
== Nützliche Artikel == | == Nützliche Artikel == | ||
* [https://www.mathworks.com/help/coder/gs/averaging-filter.html Generate C/C++ Code from a MATLAB Function] | * [https://www.mathworks.com/help/coder/gs/averaging-filter.html Generate C/C++ Code from a MATLAB Function] | ||
* [https://www.mathworks.com/help/coder/ug/unit-test-external-c-code-with-matlab-coder.html Unit Test External C Code with MATLAB Coder] | * [https://www.mathworks.com/help/coder/ug/unit-test-external-c-code-with-matlab-coder.html Unit Test External C Code with MATLAB Coder] | ||
* [https://www.mathworks.com/videos/unit-testing-c-code-using-matlab-and-matlab-coder-115878.html Unit Testing C Code Using MATLAB and MATLAB Coder] | |||
* [https://www.mathworks.com/help/coder/ug/edge-detection-with-sobel-method-in-half-precision.html Generate Code for Sobel Edge Detection That Uses Half-Precision Data Type] | * [https://www.mathworks.com/help/coder/ug/edge-detection-with-sobel-method-in-half-precision.html Generate Code for Sobel Edge Detection That Uses Half-Precision Data Type] | ||
* [https://www.mathworks.com/videos/matlab-to-c-made-easy-81870.html MATLAB to C/C++ Made Easy] | |||
* [https://matlabacademy.mathworks.com/details/matlab-coder-onramp/ormc MATLAB Coder Onramp - Self-Paced Online Courses] | |||
* [https://www.mathworks.com/support/search.html/videos/integrating-matlab-and-c-part-1-introduction-108180.html?fq%5B%5D=asset_type_name:video&fq%5B%5D=category:signal/index&page=1 Integrating MATLAB and C/C++, Part 1] | |||
* [https://www.mathworks.com/support/search.html/videos/integrating-matlab-and-c-part-2-visualizing-and-testing-cc-code-108182.html?fq%5B%5D=asset_type_name:video&fq%5B%5D=category:signal/index&page=1 Visualizing and Testing C/C++ Code | Integrating MATLAB and C/C++, Part 2] |
Aktuelle Version vom 8. September 2024, 13:31 Uhr

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