La traduction de cette page n'est pas à jour. Cliquez ici pour voir la dernière version en anglais.
Appeler Python à partir de MATLAB
Vous pouvez accéder aux bibliothèques Python directement depuis MATLAB en ajoutant le préfixe py. au nom Python. Consultez Access Python Modules from MATLAB. Par exemple :
py.list({'This','is a','list'}) % Call built-in function list
py.textwrap.wrap('This is a string') % Call wrap function in module textwrappyrun ou pyrunfile. Par exemple :pyrun("l = ['A','new','list']") % Call list in Python interpreterSi au lieu de cela vous souhaitez appeler des fonctions MATLAB depuis des applications Python, consultez Appeler MATLAB à partir de Python pour plus d’informations.
Fonctions
Tâches du Live Editor
| Run Python Code (Exécuter du code Python) | Run Python statements or script files in the Live Editor (depuis R2024a) |
Rubriques
Utiliser des bibliothèques Python dans MATLAB
- Access Python Modules from MATLAB
Create and use a Python object in MATLAB. - Configurer votre système pour utiliser Python
Comment vérifier que vous avez installé une version supportée de 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.
Exécuter du code Python depuis MATLAB
- Appeler directement les fonctionnalités Python depuis MATLAB
Méthodes pour appeler Python à partir de MATLAB.
Transmettre des données
- 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.
Résolution des problèmes
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.
