Randomly selecting images from a directory
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I have a directory of 10000 JPEG files. I want to write a script that can randomly select 100 images from this directory and save these images to a new folder on my desktop. How do I do this?
Thank you!
댓글 수: 0
채택된 답변
J. Alex Lee
2021년 5월 25일
Use "dir" and "randperm"
댓글 수: 4
J. Alex Lee
2021년 5월 25일
eagle eyes! yea, i have nothing really to add to what Jan answered in previous post.
추가 답변 (1개)
Image Analyst
2021년 5월 25일
This is how I'd do it:
fileList = dir('*.jp*');
numFiles = length(fileList)
orderToUse = randperm(numFiles);
for k = 1 : numFiles
% Get what random index this one is.
index = orderToUse(k);
% Construct the full filename.
fullFileName = fullfile(fileList(index).folder, fileList(index).name);
fprintf('Processing #%d of %d:\n which is file #%d in the list : %s\n',...
k, numFiles, index, fullFileName);
% Now do something with the file....
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!