Chiamata di Python da MATLAB
È possibile accedere direttamente alle librerie di Python da MATLAB aggiungendo il prefisso py. al nome Python. Vedere Accedi ai moduli di Python da MATLAB - Come iniziare. 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 delle librerie Python in MATLAB
- Accedi ai moduli di Python da MATLAB - Come iniziare
Come creare e utilizzare un oggetto Python in MATLAB. - Configurazione del sistema per utilizzare Python
Come 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 which might be unfamiliar to MATLAB users. - Advanced Topics
Code pattern differences you should be aware of. - 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
Modi di chiamare Python da MATLAB.
Dati passanti
- Pass MATLAB Data to Python
How Python Interface converts MATLAB data into compatible Python data types. - Handle Data Returned from Python Function
MATLAB automatically converts these data types returned from Python functions to MATLAB types. - Access Elements in Python Container Types
A Python container is typically a sequence type (listortuple) or a mapping type (dict). - Use MATLAB Datetime Types with Python
MATLAB supports conversions between MATLABdatetimevalues and Pythondatetimeor NumPydatetime64values. - Use MATLAB Duration Types with Python
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
Tips to determine if an error originates in Python or MATLAB code.
Unable to resolve the name py.myfunc
Troubleshooting failures loading Python.
Python features not supported in MATLAB.
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.
