how to display images in separate figures?
11 views (last 30 days)
Show older comments
I have already implemented my images I need to work with in matlab with imread
Now I want to open each image in one figure. I want to know how I can it open them without wirting severel times the same thing.
I tried it like this but it doesn't work:
for k = 1:8
name = ['im', num2str(k)];
figure; imshow(name)
end
0 Comments
Answers (2)
Image Analyst
on 30 May 2020
What is the extension? Let's say it's png, and you have im1.png, im2.png, etc. So see the FAQ: https://matlab.fandom.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
You need to do something like this:
% Read im1.png through im8.png. Files are in the current directory.
% Change the call to fullfile() if you need to prepend some other folder than the current folder.
for k = 1 : 8
% Create an image filename, and read it in to a variable called thisImage.
baseFileName = sprintf('im%d.png', k);
fullFileName = fullfile(pwd, baseFileName);
if isfile(fullFileName)
thisImage = imread(fullFileName);
else
fprintf('File %s does not exist.\n', fullFileName);
end
% Display the image.
figure % Bring up a new figure;
imshow(thisImage, []);
axis('on', 'image');
caption = sprintf('"%s"', baseFileName);
title(caption, 'FontSize', 15);
end
0 Comments
madhan ravi
on 30 May 2020
for k = 1:8
figure(k)
I = imread(sprintf('im%d',k)); % you forgot to read the image
imshow(I)
end
9 Comments
See Also
Categories
Find more on Display Image 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!