Scrittura di funzioni C++ chiamabili da MATLAB (file MEX)
Utilizzare l’API MEX C++ per creare funzioni di MATLAB che offrano l'efficienza dei programmi C++ e che possano accedere a funzioni e librerie esterne da MATLAB. L'API MEX C++ offre queste feature:
Utilizza le feature moderne di programmazione C++ e la progettazione orientata all’oggetto.
Chiama le funzioni di MATLAB dalla funzione MEX.
Si integra con MATLAB senza soluzione di continuità ricevendo gli input e restituendo gli output a MATLAB.
Supporta i tipi di dati di MATLAB e la semantica copy-on-write.
Scrive funzioni MEX multi-thread a prova di thread.
Esegue le funzioni C++ MEX fuori dal processo.
Nota
Le funzioni delle API C++ di MATLAB utilizzano la classe matlab::data::Array
definita nel API dei dati di MATLAB per C++. Se le funzioni MEX devono essere eseguite in MATLAB R2017b, o release precedenti, o se si preferisce lavorare in linguaggio C, utilizzare API Matrix C che lavora invece con la struttura di dati mxArray
. Per maggiori informazioni, vedere Scrittura di funzioni C richiamabili da MATLAB (MEX Files).
Argomenti
Creazione di funzioni C++ MEX
- C++ MEX Functions
MEX files implement MATLAB functions written in C++. - Create a C++ MEX Source File
How to create a basic C++ MEX function.
Impostazione e costruzione di file MEX
- Build C++ MEX Programs
Build MEX applications on different platforms. - Test Your Build Environment
Test your build environment with a predefined C++ MEX file. - C++ MEX API
Use C++11 features and the C++ Engine API to implement MEX functions.
Progettazione di funzioni C++ MEX
- Structure of C++ MEX Function
Implement a class that overrides the function call operator()
to create a functor object. - Avoid Copies of Arrays in MEX Functions
Techniques to avoid making copies of large arrays to reduce memory usage and improve execution speed. - Managing External Resources from MEX Functions
Customize theMexFunction
class to better handle the resources used by your MEX function. - Handling Inputs and Outputs
Check the size and type of inputs and display error messages in MATLAB. - Displaying Output in MATLAB Command Window
MEX functions can display output in the MATLAB command window. - Making async Requests Using mexCallMATLAB
Behavior when calling back into MATLAB with anasync
request likematlab::engine::MATLABEngine::fevalAsync
.
Tipi di dati MATLAB nelle funzioni MEX
- Data Access in Typed, Cell, and Structure Arrays
Cell and structure arrays let you write to array contents without copying entire array. - Data Types for Passing MEX Function Data
Define the correct data types to pass data between MATLAB and MEX functions.
Chiamata delle funzioni di MATLAB
- Call MATLAB Functions from MEX Functions
Call MATLAB functions, passing arguments from and returning arguments to a MEX function. - Catch Exceptions in MEX Function
Catch exceptions thrown in a MEX function. - Execute MATLAB Statements from MEX Function
Execute MATLAB statements to create variables in the caller's workspace.
Separazione dei thread e dei processi
- Call MATLAB from Separate Threads in MEX Function
MEX functions can call MATLAB from user-created threads using the C++ Engine asynchronous API. - Out-of-Process Execution of C++ MEX Functions
Execute C++ MEX functions in processes that are separate from the MATLAB process.
Accesso alle variabili di MATLAB
- Set and Get MATLAB Variables from MEX
Put variables into or get variables from the MATLAB base and global workspaces. - MATLAB Objects in MEX Functions
Pass MATLAB objects to MEX functions. - Using MEX Functions for MATLAB Class Methods
You can use MEX functions to implement methods for MATLAB classes.