Hauptinhalt

Die Übersetzung dieser Seite ist veraltet. Klicken Sie hier, um die neueste Version auf Englisch zu sehen.

Aufrufen von Python aus MATLAB heraus

Direktaufruf von Python®-Funktionen 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 textwrap
Sie können Python-Anweisungen im Python Interpreter direkt aus MATLAB heraus ausführen. Verwenden Sie dazu die Funktion pyrun oder pyrunfile. Beispiel:
pyrun("l = ['A','new','list']")  % Call list in Python interpreter
Weitere Informationen finden Sie unter Direktaufruf von Python-Funktionen aus MATLAB heraus.

Weitere Informationen dazu, wie Sie stattdessen MATLAB-Funktionen aus Python Anwendungen heraus aufrufen, erhalten Sie unter Aufrufen von MATLAB aus Python heraus.

Funktionen

alle erweitern

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

Live Editor Tasks

Ausführen von Python-CodeRun Python statements or script files in the Live Editor (Seit R2024a)

Themen

Nutzung von Python-Bibliotheken in MATLAB

Ausführen von Python-Code aus MATLAB heraus

Weitergabe von Daten

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.

Limitations to Python Support

Some Python features are not currently 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

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.

Enthaltene Beispiele