Nozioni di base sulla progettazione dell’algoritmo
La generazione di codice dagli algoritmi di MATLAB® consente di progettare, implementare e testare il software completamente all'interno del workspace di MATLAB. È possibile:
Verificare che gli algoritmi siano adatti alla generazione di codice
Generare automaticamente codice C/C++ efficiente, leggibile e compatto, eliminando la traduzione manuale e riducendo al minimo il rischio di introdurre errori nel codice.
Modificare la progettazione nel codice MATLAB per tenere conto dei requisiti specifici delle applicazioni desktop ed embedded, come la gestione del tipo di dati, l'utilizzo della memoria e la velocità.
Testare il codice generato e verificare facilmente che gli algoritmi modificati siano funzionalmente equivalenti agli algoritmi originali di MATLAB.
Generare funzioni MEX per accelerare gli algoritmi di MATLAB o velocizzare il codice MATLAB in virgola fissa.
Generare il linguaggio di descrizione hardware (HDL) dal codice MATLAB.
Per generare codice C/C++ o MEX dagli algoritmi di MATLAB, è necessario disporre di MATLAB Coder™ e di un compiler C/C++ installato.
Funzioni
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 C structure type in generated code |
coder.extrinsic | Dichiarare la funzione come estrinseca ed eseguirla in MATLAB |
coder.inline | Control inlining of current function in generated code |
coder.inlineCall | Inline called function in generated code (Da 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 (Da 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.screener | Determine if function is suitable for code generation |
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 |
Classi
coder.ExternalDependency | Interface to external code |
coder.BuildConfig | Build context during code generation |
Argomenti
- 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.
- Code Generation Readiness Tool
The code generation readiness tool screens MATLAB code for features and functions that code generation does not support.
- Check Code Using the Code Generation Readiness Tool
Run the code generation readiness tool at the command line or from the Files panel.
- 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.
Risoluzione dei problemi
Unknown Output Type for coder.ceval
Define the output type for external C/C++ function calls.