How to randomly extract 50 images from a file?

3 visualizaciones (últimos 30 días)
AK
AK el 11 de Mzo. de 2021
Comentada: Jan el 11 de Mzo. de 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!

Respuesta aceptada

Jan
Jan el 11 de Mzo. de 2021
Editada: Jan el 11 de Mzo. de 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 comentarios
AK
AK el 11 de Mzo. de 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 el 11 de Mzo. de 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)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by