Chiamata di Python da MATLAB
È possibile accedere direttamente alle librerie di Python da MATLAB aggiungendo il prefisso py. al nome Python. Vedere Accesso ai moduli di Python da MATLAB. 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 textwrappyrun o pyrunfile. Ad esempio:pyrun("l = ['A','new','list']") % Call list in Python interpreterSe invece si desidera chiamare le funzioni di MATLAB dalle applicazioni di Python, vedere Chiamata di MATLAB da Python per maggiori informazioni.
Funzioni
Attività di Live Editor
| Eseguire il codice Python | Run Python statements or script files in the Live Editor (Da R2024a) |
Argomenti
Utilizzo degli ambienti Python in MATLAB
- Manage Python Environments Using External Languages Panel
You can use the Python view in the External Languages panel to configure and maintain your Python environments directly from MATLAB.
Utilizzo delle librerie Python in MATLAB
- Accesso ai moduli di Python da MATLAB
Creare e utilizzare un oggetto Python in MATLAB. - Configurazione del sistema per utilizzare Python
Verificare di aver installato una versione supportata di Python. - Call User-Defined Python Module
Create a Python module used by examples in this documentation. - Understand Python Function Arguments
Python method syntax differs from MATLAB method syntax. - Advanced Topics
Learn about code pattern differences between MATLAB and Python. - Out-of-Process Execution of Python Functionality
Execute Python scripts in processes that are separate from the MATLAB process. - Reload Out-of-Process Python Interpreter
Reload out-of-process Python interpreter without restarting MATLAB.
Esecuzione del codice Python da MATLAB
- Chiamata diretta di funzionalità Python da MATLAB
Chiamare le funzionalità dalle librerie di Python o eseguire dichiarazioni Python direttamente da MATLAB.
Dati passanti
- Pass Data Between MATLAB and Python from MATLAB
The Python interface converts MATLAB data into compatible Python data types. - Access Elements in Python Container Types
A Python container is typically a sequence type (listortuple) or a mapping type (dict). - Use Python Datetime Types in MATLAB
MATLAB supports conversions between MATLABdatetimevalues and Pythondatetimeor NumPydatetime64values. - Use Python Duration Types in MATLAB
MATLAB supports conversions between MATLABdurationvalues and Pythontimedeltaor NumPytimedelta64values. - Pass Python Function to Python map Function
This example shows how to display the length of each word in a list.
Risoluzione dei problemi
Determine If Error is Python or MATLAB Error
Determine if an error originates in Python or MATLAB code.
Unable to resolve the name py.myfunc
Troubleshoot failures loading Python.
Some Python features are not currently supported in MATLAB.
MATLAB catches exceptions thrown by Python and converts them into a matlab.exception.PyException object.
Troubleshooting Matrix and Numeric Argument Errors
Errors might be caused by an input array with more than one dimension whose size is greater than 1.
Error Converting Elements of list or tuple
Use string and numeric converters for list and
tuple types.
Esempi in primo piano
Risorse didattiche
Programmazione: un progetto iniziale utilizzando MATLAB con Python
Scoprire come chiamare il codice Python, convertire i tipi di dato e le unità e utilizzare App Designer per costruire un'app che mostri i risultati.

