Yaml files. Python object to Matlab object conversion.

Versión 1.0.0 (10,9 KB) por gts
Covert Python objects from .yaml files.
3 Descargas
Actualizado 15 ene 2026

Ver licencia

Function p2m.m addresses the need to read .yaml files. Since .yaml files are inherently Pythonic, it is more appropriate to let Python handle the parsing of the YAML content and then convert the resulting Python objects into MATLAB objects, rather than implementing complex MATLAB code to read .yaml files directly (MATLAB only solutions exist on File Exchange). But this approach calls for a function that converts Python objects to MATLAB objects.
Numerous Python-to-MATLAB conversion functions can be found online, with the earliest example being py2mat.m by Al Danial (https://al.danial.org/posts/py2mat_mat2py_speedup/), however p2m.m is a bit more advanced and modular.
Converting Python objects to MATLAB objects is not always a one-to-one relationship: it can be one-to-many or many-to-one. For instance, Python dictionaries may be converted to either MATLAB structures or MATLAB dictionary objects, while Python lists and tuples map to MATLAB cell arrays. Consequently, multiple conversion options exist. Some Python data container types, such as e.g. set or frozenset, have no direct MATLAB equivalent. For this reason, p2m.m is designed to be easily extensible, allowing users to add or customize conversions as needed, suiting their own preferences. Rather than relying solely on automatic conversions, p2m.m provides manual flags that allow the user to explicitly select among available conversion options. The function is accompanied by a collection of .yaml test files and a test bench script, yaml_read_tb.m (requiring Python yaml module), enabling users to evaluate and validate its behavior. Finally, as p2m.m is a recursive function, it may contain bugs; users should therefore exercise caution. Improvements are welcome.
Hopefully, MathWorks will eventually provide a built-in, standardized set of Python <--> MATLAB conversion functions to address the topic.

Citar como

gts (2026). Yaml files. Python object to Matlab object conversion. (https://es.mathworks.com/matlabcentral/fileexchange/183066-yaml-files-python-object-to-matlab-object-conversion), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2025b
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Etiquetas Añadir etiquetas

read_yaml

Versión Publicado Notas de la versión
1.0.0