how to select the last image from folder in matlab

3 views (last 30 days)
I have a lot of pictures and saved in a folder. The images in the folder can continue to grow. I should be able to display the last image that goes into the folder automatically without changing the code.
The code I use:
path = 'E: \ MATLAB Program \ Skrice \ bacteria';
jpeg_files = dir (fullfile (path, '*. jpg'));
for cnt = 43
     I {cnt} = imread (fullfile (path, jpeg_files (cnt) .name));
     figure, imshow (I {cnt});
end
the code is not flexible. Please help. Thank you.

Answers (1)

the cyclist
the cyclist on 11 Apr 2018
If you call the dir command and assign it to an output ...
fileList = dir
then fileList is a structure, and fileList.date has the file dates.
  3 Comments
the cyclist
the cyclist on 13 Apr 2018
The images will not necessarily be listed in time order. You'll need to take those times as an input, and write some code to find the latest time. If you don't know how to do that, I suggest opening a second question specifically about that.
Stephen23
Stephen23 on 13 Apr 2018
Edited: Stephen23 on 13 Apr 2018
"do you mean the image will be displayed in sequence of time?"
The order of the output of dir is not specified:
  • If you want the files in alphabetical order you will have to sort them yourself: you have the names.
  • If you want the files in chronological order then you will have to sort them yourself: you have the dates.
  • If you want the files listed in size order you will have to sort them yourself: you have the file sizes.
  • etc.

Sign in to comment.

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!