Loading a random file from a directory

조회 수: 8 (최근 30일)
Kevin Akash Rajasekaran
Kevin Akash Rajasekaran 2021년 6월 24일
댓글: Kevin Akash Rajasekaran 2021년 7월 1일
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개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by