MATLAB-Coder: Unterschied zwischen den Versionen

Aus HSHL Mechatronik
Zur Navigation springen Zur Suche springen
 
Zeile 26: Zeile 26:
== Configure Generated Code ==
== 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.
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 ==

Aktuelle Version vom 8. September 2024, 14:31 Uhr

Abb. 1: MATrix LABoratory (MATLAB®)
Autor: Prof. Dr.-Ing. Schneider

Code Generation Requirements

The three most common code generation issues are solved with these preparation steps:

  1. Define function input variables.
  2. Preallocate arrays before indexing.
  3. 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:

  1. in a test script to verify the generated code
  2. 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