How to randomly extract 50 images from a file?

조회 수: 3 (최근 30일)
AK
AK 2021년 3월 11일
댓글: Jan 2021년 3월 11일
Hello!
I am new to Matlab, so please bear with me. I have a file containing thousands of images. I am trying to randomly select 50 images and save it into a new file.
This is the code im trying to use.
Dest = '/Users/Desktop/Image Dataset';
FileList = '/Users/Downloads/ILSVRC2012_img_val';
Index = randperm(50, numel(FileList));
for k = 1:50
Source = FileList(Index(k)).name;
copyfile(Source, Dest);
end
But I keep getting error "Dot indexing is not supported for variables of this type". How do i fix this?
Thank you!

채택된 답변

Jan
Jan 2021년 3월 11일
편집: Jan 2021년 3월 11일
Dest = '/Users/Desktop/Image Dataset';
FileList = dir('/Users/Downloads/ILSVRC2012_img_val/*.jpg'); % DIR command was missing
% and perhaps
% the pattern
Index = randperm(numel(FileList), 50); % Swap order of arguments
for k = 1:50
Source = FileList(Index(k)).name;
copyfile(Source, Dest);
end
  댓글 수: 2
AK
AK 2021년 3월 11일
Thank you! this helped.
I made the changes you suggested. However, now i recieve the error " error using copyfile. arguement must be text scalar"
Do you know what i could be doing wrong here? Thanks!
Jan
Jan 2021년 3월 11일
Use the debugger to find out, what the variable is. Type this in the command window:
dbstop if error
Then run the code. When Matlab stops at the error, check the arguments of COPYFILE:
class(Source)
size(Source)
class(Dest)
size(Dest)

댓글을 달려면 로그인하십시오.

추가 답변 (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