Loading a random file from a directory

8 visualizaciones (últimos 30 días)
Kevin Akash Rajasekaran
Kevin Akash Rajasekaran el 24 de Jun. de 2021
Comentada: Kevin Akash Rajasekaran el 1 de Jul. de 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!

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by