List all matlab files in python

17 ビュー (過去 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 Center および File ExchangeCall Python from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by