MATLAB Answers

how to read series of images from folder in specific order?

30 views (last 30 days)
sana3 sal
sana3 sal on 17 Jul 2018
Hello there, I am trying to read jpg files from folder with a series of A1,A2,....A22 but when i read them with the following code they read A1,A10,A11,A12...etc then A2,A20,A21 .. etc alphabetically! how i can read them in my specific order?
myFolder = 'C:\Users\JUST\Downloads\Sana3';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.jpg'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray = imread(fullFileName);
%imshow(imageArray); % Display image.

Sign in to comment.

Answers (1)

Diwakar Ravichandran
Diwakar Ravichandran on 18 Jul 2018
As the solution is already given by @dpb please close this question so that it is off the unanswered questions list. Thank you

Community Treasure Hunt

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

Start Hunting!

Translated by