Aufrufen von MATLAB aus C heraus
mxArrayBei Engine-Anwendungen handelt es sich um Programme, mit denen Sie MATLAB aus Ihren eigenen C/C++ Programmen heraus aufrufen können (unter Verwendung von MATLAB als Berechnungskern). Rufen Sie zur Erstellung einer C Engine-Anwendung die Funktion mex auf.
Hinweis
Das MATLAB-Engine-API für C++ sollte gegenüber dem Engine-API für C bevorzugt werden. Das MATLAB-Engine-API für C++ umfasst moderne C++ Funktionen zum Erstellen von Engine-Anwendungen. Weitere Informationen finden Sie unter Aufrufen von MATLAB aus C++ heraus. Das Entfernen des Engine-API for C ist nicht vorgesehen.
Für Engine-Anwendungen ist eine installierte Version von MATLAB erforderlich. Sie können die MATLAB-Engine nicht auf einem Rechner ausführen, auf dem sich nur die MATLAB-Runtime befindet.
Zur Erstellung einer C Engine-Anwendung benötigen Sie:
Erfahrung im Erstellen von Quellcode in C. Sie können C Quellcodedateien mithilfe des Engine-API für C und C Matrix-API-Funktionen erstellen.
Einen von MATLAB unterstützten Compiler. Eine aktuelle Liste der unterstützten Compiler finden Sie unter Unterstützte und kompatible Compiler.
Verwenden Sie das
mexBuild-Skript mit der Option-client engine.
Engine-API für 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 |
Themen
Anforderungen
- 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.
Verfassen von Engine-Anwendungen
- 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.
Erstellen und Ausführen von Engine-Anwendungen
- 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.
Fehlersuche
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.