Loading a random file from a directory

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

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 File Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by