Aufrufen von Python aus MATLAB heraus
Sie können auf Python-Bibliotheken direkt aus MATLAB heraus zugreifen, indem Sie das Präfix py. vor den Python-Namen setzen. Siehe Access Python Modules from MATLAB. Beispiel:
py.list({'This','is a','list'}) % Call built-in function list
py.textwrap.wrap('This is a string') % Call wrap function in module textwrappyrun oder pyrunfile. Beispiel:pyrun("l = ['A','new','list']") % Call list in Python interpreterWeitere Informationen dazu, wie Sie stattdessen MATLAB-Funktionen aus Python Anwendungen heraus aufrufen, erhalten Sie unter Aufrufen von MATLAB aus Python heraus.
Funktionen
Live Editor Tasks
| Ausführen von Python-Code | Run Python statements or script files in the Live Editor (Seit R2024a) |
Themen
Nutzung von Python-Bibliotheken in MATLAB
- Access Python Modules from MATLAB
Create and use a Python object in MATLAB. - Konfigurieren Ihres Systems zum Verwenden von Python
So können Sie überprüfen, ob Sie eine unterstützte Version von Python installiert haben. - 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.
Ausführen von Python-Code aus MATLAB heraus
- Direktaufruf von Python-Funktionen aus MATLAB heraus
Möglichkeiten zum Aufruf von Python von MATLAB aus
Weitergabe von Daten
- 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.
Fehlersuche
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.
