List all matlab files in python

조회 수: 11 (최근 30일)
John
John 2022년 10월 3일
댓글: John 2022년 10월 5일
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
Geoff Hayes
Geoff Hayes 2022년 10월 3일
@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 2022년 10월 4일
Yes, I want to list all the matlab files in python. Thank you for the help.

댓글을 달려면 로그인하십시오.

답변 (1개)

Al Danial
Al Danial 2022년 10월 4일
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.
  댓글 수: 1
John
John 2022년 10월 5일
Very helpful. Thank you!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by