Borrar filtros
Borrar filtros

List all matlab files in python

16 visualizaciones (últimos 30 días)
John
John el 3 de Oct. de 2022
Comentada: John el 5 de Oct. de 2022
Hi. I need to convert the following matlab code to python:
DirList = dir(fullfile(Folder, '*.mat'));
Data = cell(1, length(DirList));
Do you have an idea of how to do it in python?
  2 comentarios
Geoff Hayes
Geoff Hayes el 3 de Oct. de 2022
@John - you may be able to use glob to get a list of files that match satisfy a filter. Are you planning to look for mat files? Will you then be trying to open them with Python?
John
John el 4 de Oct. de 2022
Yes, I want to list all the matlab files in python. Thank you for the help.

Iniciar sesión para comentar.

Respuestas (1)

Al Danial
Al Danial el 4 de Oct. de 2022
As @John mentioned, one way is with the glob function from the module of the same name:
from glob import glob
Dir = '.'
mat_files = glob(f'{Dir}/*.mat')
to create the Python list mat_files.

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by