Loading a random file from a directory

5 Ansichten (letzte 30 Tage)
Kevin Akash Rajasekaran
Kevin Akash Rajasekaran am 24 Jun. 2021
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!

Akzeptierte Antwort

KSSV
KSSV am 24 Jun. 2021
Bearbeitet: KSSV am 24 Jun. 2021
matFiles = dir('*.mat') ;
N = length(matFiles) ;
thisFile = matFiles(randperm(N,1)).name

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by