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 - Getting Started. 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
pyrun
oder pyrunfile
. Beispiel:pyrun("l = ['A','new','list']") % Call list in Python interpreter
Weitere 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 - Getting Started
How to create and use a Python object in MATLAB. - Configure Your System to Use Python
How to verify you have installed a supported version of 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.
Ausführen von Python-Code aus MATLAB heraus
- Directly Call Python Functionality from MATLAB
Ways to call Python from MATLAB.
Weitergabe von Daten
- Pass MATLAB Data to Python
How MATLAB 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 (list
ortuple
) or a mapping type (dict
). - Use MATLAB datetime Types with Python
MATLAB supports conversions between MATLABdatetime
values and Pythondatetime
or NumPydatetime64
values. - Use MATLAB duration Types with Python
MATLAB supports conversions between MATLABduration
values and Pythontimedelta
or NumPytimedelta64
values. - 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
Tips to determine if an error originates in Python or MATLAB code.
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.