How can I have my code access multiple images automatically?

I have multiple images in a folder, for example 'img1, img2, img3' How can I make my code access those files with specified names automatically? I've been using uigetfile and imread but both require manual input.

 Respuesta aceptada

Joseph Cheng
Joseph Cheng el 7 de Ag. de 2014
you can use the function dir() such as files = dir('*.jpg') which will return the file information for each jpeg into a structure. then a simple for-loop to access files.name (given my example of files) to loop through the jpegs in the folder.

1 comentario

Joseph Cheng
Joseph Cheng el 7 de Ag. de 2014
Editada: Joseph Cheng el 7 de Ag. de 2014
air coding so pardon function call mistakes:
folder = uigetfolder();
jpegfiles = dir(fullfile(folder,'*.jpg'));
for imageNum = 1:length(jpegfiles)
importedImage(imageNum).raw = imread(fullfile(folder,jpegfiles(imageNum).Name));
end

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 7 de Ag. de 2014

Editada:

el 7 de Ag. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by