Appeler MATLAB à partir de C
mxArrayLes applications Engine sont des programmes qui vous permettent d’appeler MATLAB depuis vos propres programmes C/C++ en utilisant MATLAB comme moteur de calcul. Pour créer une application Engine C, appelez la fonction mex.
Remarque
Il est recommandé d’utiliser MATLAB Engine API pour C++ plutôt qu’Engine API pour C. MATLAB Engine API pour C++ propose les fonctionnalités du C++ moderne pour écrire des applications Engine. Pour plus d’informations, consultez Appeler MATLAB à partir de C++. Il n’est pas prévu de supprimer Engine API pour C.
Les applications Engine nécessitent une version installée de MATLAB. Vous ne pouvez pas exécuter MATLAB Engine sur un ordinateur seulement équipé de MATLAB Runtime.
Pour créer une application Engine C, il vous faut :
Une bonne expérience de l’écriture de code source C. Vous pouvez créer des fichiers de code source C avec Engine API pour C et les fonctions C Matrix API.
Un compilateur supporté par MATLAB. Pour une liste à jour des compilateurs supportés, consultez Supported and Compatible Compilers (Compilateurs supportés et compatibles).
Utiliser le script de compilation
mexavec l’option-client engine.
Engine API pour C
Engine | Type for MATLAB engine |
engOpen | Start MATLAB engine session |
engOpenSingleUse | Start MATLAB engine session for single, nonshared use |
engClose | Quit MATLAB engine session |
engEvalString | Evaluate expression in string |
engGetVariable | Copy variable from MATLAB engine workspace |
engPutVariable | Put variable into MATLAB engine workspace |
engGetVisible | Determine visibility of MATLAB engine session |
engSetVisible | Show or hide MATLAB engine session |
engOutputBuffer | Specify buffer for MATLAB output |
Rubriques
Configuration requise
- Requirements to Build Engine C Applications
Install and configure a compiler and run-time environment so you can build C applications to call MATLAB. - Set Up C Development Environment
Set up a development environment to write C applications that call MATLAB functions.
Écrire des applications Engine
- MATLAB Engine APIs for C and Fortran
Call MATLAB from your own C and Fortran programs, using MATLAB as a computation engine. - Call MATLAB Functions from C Applications
Create a C engine applicationengdemo.c. - Attach to Existing MATLAB Sessions
This example shows how to attach an engine program to a MATLAB session on a Windows® platform that is already running. - Callbacks in Applications
Design user interface callbacks to be evaluated in the context of the base workspace.
Créer et exécuter des applications Engine
- Build and Run C Engine Application on Windows
This example shows how to verify the build process on a Windows platform. - Build and Run C Engine Application on macOS
This example shows how to verify the build process on a macOS platform. - Build and Run C Engine Application on Linux
This example shows how to verify the build process on a Linux® platform.
Résolution des problèmes
What to do when MATLAB engine does not run.
Debug MATLAB Function Called by C Engine
How to verify MATLAB functions used in engine applications.
Some MATLAB functions that interact with the user are not supported in engine applications.
MATLAB libraries are not thread-safe.