how to display images in separate figures?

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

Answers (2)

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
for k = 1:8
figure(k)
I = imread(sprintf('im%d',k)); % you forgot to read the image
imshow(I)
end

9 Comments

but I have already my images with:
im1 = imread('file path');
and this 8 times
Do I have to read the image again? Because it doesn't work neither with this code
I can't help unless you reveal what 'file path' is.
like C:\user\etc...
madhan ravi
madhan ravi on 30 May 2020
Edited: madhan ravi on 30 May 2020
You need to be more precise, if you want a more precise answer.
sorry I forgot to write .jpg in my last comment.
I already have implemented the images I need with
im1 = imread('C:\image.jpg')
I did this for every picture. Then I let Matlab show me the image with
imshow(im1)
I want that Matlab opens me every picture in a separate figure without writing imshow several times
How are your images named? If it’s named image1-image8 then
I = imread(sprintf('C:\image%d.jpg',k));
no they are named like camera standard picture names like D003892 something like this, but I can to rename them
Man you are complicating a simple problem.

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Asked:

on 30 May 2020

Answered:

on 30 May 2020

Community Treasure Hunt

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

Start Hunting!