How to read and display multiple images in matlab

2 views (last 30 days)
Hi there
I'm trying to read an images from the folder using for loop but when i run the code it doesn't work
Here is my code:
folder='Documents/MATLAB/*.png' ;
for k=1:numel(I)

Answers (3)

Adam on 10 Mar 2017
Your code is equivalent to:
fullfile( 'Documents/MATLAB/*.png', '*.png' );
which is clearly not going to resolve to something sensible. dir just needs a folder given to it, not filenames with extensions.
Adam on 10 Mar 2017
Useful to know. I've only used dir on folders so far!

Sign in to comment.

Thorsten on 10 Mar 2017
Edited: Thorsten on 10 Mar 2017

Image Analyst
Image Analyst on 10 Mar 2017
Edited: Image Analyst on 10 Mar 2017
Like Adam said, see the FAQ for two code samples:
A glaring problem with your code is the lack of any way to show/display the images. There is no imshow(a) in your loop. Other problems include no using "drawnow" to see the images after each one, otherwise you'll just see the last images. And using horrible variable names like the badly-named a.
See attached demo.


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!