When you call a Python method or function, MATLAB converts the input arguments into types that best represent the data to the Python language.
MATLAB automatically converts most Python numeric data into MATLAB types. For other data types, use MATLAB functions to explicitly convert Python data types to MATLAB types.
pyargs | Create keyword argument for Python function |
List, Tuple, and Dictionary Types
Commands for creating list
, tuple
,
and dict
types.
When calling a Python function, MATLAB converts MATLAB data into types that best represent the data to the Python language.
Handle Data Returned from Python
How MATLAB converts data returned from Python into MATLAB types.
Access Elements in Python Container Types
A Python container is typically a sequence type
(list
or tuple
) or a mapping
type (dict
).
Pass MATLAB Character Vector to Python Method
This example shows how to display the contents
of a folder using the Python os.listdir
method.
This example shows how to use the Python® path separator character (;
).
This example shows how to display the first character of a Python® str
variable.
Pass MATLAB Backslash Control Character
This example shows how to pass the backslash control character (\
) as a Python® str
type.
This example shows how to create a list
variable to pass to a Python® function.
Use Python list Type in MATLAB
This example shows how to display folders on
your system using the MATLAB disp
function
on the Python sys.path
variable.
Use Python List of Numeric Types in MATLAB
This example shows how to convert a Python® list of numeric values into a MATLAB® array of double.
This example shows how to display the last element in a Python® list
variable.
Use Python List as Values in for Loop
This example shows how to display elements of a Python® list.
Pass Cell Array as Python Sequence Type
This example shows how to pass a MATLAB cell array to a Python function.
Read Element of Nested list Type
This example shows how to access an element of a Python® list
variable containing list
elements.
Display Stepped Range of Python Elements
This example shows how to use an incremental step in indexing.
This example shows how to create a tuple
variable to pass to a Python® function.
This example shows how to display elements in a tuple.
Create Singleton Python tuple Variable
This example shows how to create a Python® tuple
variable with a single element.
This example shows how to create a dict
variable to pass to a Python® function.
Use Python dict Type in MATLAB
This example shows how to convert numerical
values of a Python dict
variable into a MATLAB array.
This example shows how to get and set values in a dictionary.
Pass dict Argument to Python Method
This example shows how to change a value in a dict
variable using the Python® update method.
Convert Python dict Type to MATLAB Structure
This example shows how to plot numeric data from a Python dictionary.
By default, a number in MATLAB is a double
type,
but a number in Python is an integer type.
Use Python Numeric Types in MATLAB
This example shows how to use Python® numbers in MATLAB®.
Call Python Methods with Numeric Arguments
This example shows how to call the Python math.fsum
function, which sums the floating-point values in an interable
input argument.
Use Python array Types in MATLAB
This example shows how to sum the elements
of a Python array.array
of type double.
This topic describes how MATLAB displays Python numeric values.
This example shows how to use Python keyword arguments in MATLAB.
Pass Python Function to Python map Function
This example shows how to display the length of each word in a list.