Main Content

La traduzione di questa pagina non è aggiornata. Fai clic qui per vedere l'ultima versione in inglese.

Chiamata di Python da MATLAB

Chiamare direttamente le funzionalità di Python® da MATLAB®

È possibile accedere direttamente alle librerie di Python da MATLAB aggiungendo il prefisso py. al nome Python. Vedere Access Python Modules from MATLAB - Getting Started. Ad esempio:

py.list({'This','is a','list'})      % Call built-in function list
py.textwrap.wrap('This is a string') % Call wrap function in module textwrap
È possibile eseguire dichiarazioni di Python nell’interprete di Python direttamente da MATLAB utilizzando le funzioni pyrun o pyrunfile. Ad esempio:
pyrun("l = ['A','new','list']")  % Call list in Python interpreter
Per maggiori informazioni, vedere Directly Call Python Functionality from MATLAB.

Se invece si desidera chiamare le funzioni di MATLAB dalle applicazioni di Python, vedere Chiamata di MATLAB da Python per maggiori informazioni.

Funzioni

espandi tutto

pyenvChange default environment of Python interpreter (Da R2019b)
PythonEnvironmentPython environment information (Da R2019b)
pyrunRun Python statements from MATLAB (Da R2021b)
pyrunfileRun Python script file from MATLAB (Da R2021b)
pyargsCreate keyword arguments for Python function
matlab.exception.PyExceptionCapture error information for Python exception

Argomenti

Utilizzo delle librerie Python in MATLAB

Esecuzione del codice Python da MATLAB

Dati passanti

Risoluzione dei problemi

Determine if Error is Python or MATLAB Error

Tips to determine if an error originates in Python or MATLAB code.

Limitations to Python Support

Python features not supported in MATLAB.

Handle Python Exceptions

MATLAB catches exceptions thrown by Python and converts them into a matlab.exception.PyException object.

Troubleshooting Matrix and Numeric Argument Errors

Error might be caused by input array with more than one non-singleton dimension.

Error Converting Elements of list or tuple

How to use string and numeric converters for list and tuple types.