Llamar a Python desde MATLAB
Puede acceder a las bibliotecas de Python directamente desde MATLAB agregando el prefijo py. al nombre Python. Consulte Acceder a módulos de Python desde MATLAB: introducción. Por ejemplo:
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. Por ejemplo:pyrun("l = ['A','new','list']") % Call list in Python interpreterSi en su lugar desea llamar a las funciones de MATLAB desde las aplicaciones de Python, consulte Llamar a MATLAB desde Python para obtener más información.
Funciones
Tareas de Live Editor
| Ejecutar código de Python | Run Python statements or script files in the Live Editor (Desde R2024a) |
Temas
Usar bibliotecas de Python en MATLAB
- Acceder a módulos de Python desde MATLAB: introducción
Cómo crear y utilizar un objeto de Python en MATLAB. - Configurar su sistema para utilizar Python
Cómo verificar que ha instalado una versión compatible de Python. - Llamar a un módulo de Python definido por el usuario
Cree un módulo de Python utilizado en ejemplos de esta documentación. - 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. - Volver a cargar un intérprete de Python fuera de proceso
Vuelva a cargar un intérprete de Python fuera de proceso sin reiniciar MATLAB.
Ejecutar código de Python desde MATLAB
- Llamar directamente a funcionalidades de Python desde MATLAB
Formas de llamar a Python desde MATLAB.
Paso de datos
- Pasar datos de MATLAB a Python
Cómo convierte la interfaz de Python datos de MATLAB en tipos de datos de Python compatibles. - 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.
Solución de problemas
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.

