Loading a random file from a directory

7 vues (au cours des 30 derniers jours)
Kevin Akash Rajasekaran
Kevin Akash Rajasekaran le 24 Juin 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!

Réponse acceptée

KSSV
KSSV le 24 Juin 2021
Modifié(e) : KSSV le 24 Juin 2021
matFiles = dir('*.mat') ;
N = length(matFiles) ;
thisFile = matFiles(randperm(N,1)).name

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by