Chiamata di MATLAB da Python
L’API di MATLAB Engine per Python fornisce un pacchetto Python per chiamare MATLAB come motore computazionale. L’engine supporta l'implementazione di riferimento (CPython). Per informazioni sulle versioni supportate, vedere Versions of Python Compatible with MATLAB Products by Release (Versioni di Python compatibili con i prodotti di MATLAB per release).
Per installare e avviare il motore, vedere Get Started with MATLAB Engine API for Python.
Per chiamare le funzioni Python da MATLAB, vedere Chiamata di Python da MATLAB.
Le applicazioni engine richiedono una versione installata di MATLAB; non è possibile eseguire MATLAB Engine su una macchina che dispone solo del runtime di MATLAB.
Funzioni
Classi
Argomenti
Installazione
- System Requirements for MATLAB Engine API for Python
What you need to write and build MATLAB engine applications for Python. - Install MATLAB Engine API for Python
To start MATLAB engine within a Python session, install the engine API as a Python package.
Come iniziare
- Get Started with MATLAB Engine API for Python
MATLAB Engine API for Python provides a Python package namedmatlab
that enables you to call MATLAB functions from Python. - Start and Stop MATLAB Engine for Python
Options for starting the MATLAB Engine for Python. - Call MATLAB Functions from Python
How to return an output argument from a MATLAB function. How to read multiple outputs from a function. What to do when the MATLAB function does not return an output argument. - Get Help for MATLAB Functions from Python
From Python, you can access supporting documentation for all MATLAB functions.
Gestione della sessione
- Connect Python to Running MATLAB Session
How to connect the MATLAB Engine for Python to a shared MATLAB session that is already running on your local machine.
Utilizzo del workspace di MATLAB
- Use MATLAB Engine Workspace in Python
This example shows how to add variables to the MATLAB engine workspace in Python.
Scambio e mappatura dei dati
- Use MATLAB Arrays in Python
This example shows how to create a MATLAB array in Python and pass it as the input argument to the MATLABsqrt
function. - MATLAB Arrays as Python Variables
Thematlab
Python module provides array classes to represent arrays of MATLAB numeric types as Python variables so that MATLAB arrays can be passed between Python and MATLAB. - Pass Data to MATLAB from Python
When you pass Python data as input arguments to MATLAB functions, the MATLAB Engine for Python converts the data into equivalent MATLAB data types. - Handle Data Returned from MATLAB to Python
When MATLAB functions return output arguments, MATLAB Engine API for Python converts the data into equivalent Python data types. - Use MATLAB Handle Objects in Python
This example shows how to create an object from a MATLAB handle class and call its methods in Python. - Default Numeric Types in MATLAB and Python
MATLAB stores all numeric values as double-precision floating point numbers by default.
Chiamata delle funzioni di MATLAB
- Call User Scripts and Functions from Python
This example shows how to call a MATLAB script to compute the area of a triangle from Python. - Sort and Plot MATLAB Data from Python
This example shows how to sort data about patients into lists of smokers and nonsmokers in Python and plot blood pressure readings for the patients with MATLAB. - Call MATLAB Functions Asynchronously from Python
This example shows how to call the MATLABsqrt
function asynchronously from Python and retrieve the square root later. - Redirect Standard Output and Error to Python
This example shows how to redirect standard output and standard error from a MATLAB function to PythonStringIO
objects.
Risoluzione dei problemi
Limitations to MATLAB Engine API for Python
MATLAB Engine API for Python does not support these features.
Troubleshoot MATLAB Errors in Python
When a MATLAB function raises an error, the MATLAB Engine for Python stops the function and catches the exception raised by MATLAB.