hi I have multiple .csv files and I want to randomly choice 1 to run how do I right the code to only choice on of them?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
James Webber
am 30 Dez. 2021
Kommentiert: James Webber
am 30 Dez. 2021
i am writing a code for the game battle ships and i need to be able to import multiple .csvfiles for the computer to run from but each game the computer needs to choice a file to use how do i make it randomly choice which file to use?
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 30 Dez. 2021
Try this:
folder = pwd; % Wherever the csv files are
filePattern = fullfile(folder, '*.csv');
% Get a directory listing.
fileList = dir(filePattern)
numFiles = length(fileList)
% Get a random index
randomIndex = randi(numFiles)
% Get the filename.
fullFileName = fullfile(fileList(randomIndex).folder, fileList(randomIndex).name)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Strategy & Logic finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!