Clear Filters
Clear Filters

Prevent Overwrite Image in loop

3 views (last 30 days)
Ashley Lewis
Ashley Lewis on 7 Aug 2018
Edited: Stephen23 on 7 Aug 2018
I am trying to load all 16 images. When I run my code now, Only the last image is saved and can be displayed. Even when I include "loadedimage= imread(Image)" and "imshow(loadedimage)" in the for loop this still occurs. Thanks for any help!
for k=1:16 fileName = strcat('image',num2str(k),'.bmp'); Image= char(fileName); end loadedimage= imread(Image); imshow(loadedimage)
  2 Comments
Magdy Saleh
Magdy Saleh on 7 Aug 2018
You are overwriting the image variable at every iteration of the loop
Ashley Lewis
Ashley Lewis on 7 Aug 2018
Ok thanks! Any way I can avoid this?

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 7 Aug 2018
Edited: Stephen23 on 7 Aug 2018
N = 16;
C = cell(1,N);
for k = 1:N
F = sprintf('image%d.bmp',k);
C{k} = imread(F);
end
All of the images will be in cell array C.

More Answers (0)

Categories

Find more on Images 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!