MATLAB: Random extraction of files from a folder

random extraction of files

I have a folder of 12000 images (in bmp format). I would like to randomly extract 2000 images and store it in a different folder. How can i do that?

Best Answer

Based on Adam's suggestions:
Dest = 'C:\Temp';
FileList = dir(fullfile(Folder, '*.bmp'));
Index = randperm(numel(FileList), 2000);
for k = 1:2000
Source = fullfile(Folder, FileList(index(k)).name);
copyfile(Source, Dest);
end
Or movefile.