random extraction of files from a folder
9 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Jan
2017-3-16
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.
更多回答(2 个)
Adam
2017-3-16
doc dir
can be used to give you a listing.
doc randperm
can be applied to your listing to select the random files. I don't have time (or inclination) to write the code for you though so feel free to ask further questions once you have made an attempt if you get stuck.
ES
2017-3-16
You can do a dir in that folder for a list of files. Use a random number generator of 2000 length.
Select the file based on the random number.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!