How to randomly extract 50 images from a file?

3 Ansichten (letzte 30 Tage)
AK
AK am 11 Mär. 2021
Kommentiert: Jan am 11 Mär. 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!

Akzeptierte Antwort

Jan
Jan am 11 Mär. 2021
Bearbeitet: Jan am 11 Mär. 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 Kommentare
AK
AK am 11 Mär. 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 am 11 Mär. 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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by