How to randomly extract 50 images from a file?

3 vues (au cours des 30 derniers jours)
AK
AK le 11 Mar 2021
Commenté : Jan le 11 Mar 2021
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!

Réponse acceptée

Jan
Jan le 11 Mar 2021
Modifié(e) : Jan le 11 Mar 2021
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 commentaires
AK
AK le 11 Mar 2021
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 le 11 Mar 2021
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)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by