Loading a random file from a directory

8 ビュー (過去 30 日間)
Kevin Akash Rajasekaran
Kevin Akash Rajasekaran 2021 年 6 月 24 日
Hey all! So I'm looking to write a program which involves randomly loading a .mat file from a directory containing a number of .mat files in a directory (C/toolbox/files). What's the best way to go about selecting a random .mat file from the directory and loading it? Thanks!

採用された回答

KSSV
KSSV 2021 年 6 月 24 日
編集済み: KSSV 2021 年 6 月 24 日
matFiles = dir('*.mat') ;
N = length(matFiles) ;
thisFile = matFiles(randperm(N,1)).name
  1 件のコメント
Kevin Akash Rajasekaran
Kevin Akash Rajasekaran 2021 年 7 月 1 日
Thanks! this worked!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by