MATLAB Answers

how to display images in separate figures?

7 views (last 30 days)
Mirsamir Salahov
Mirsamir Salahov on 30 May 2020
Answered: Image Analyst on 30 May 2020
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

Sign in to comment.

Answers (2)

Image Analyst
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

Sign in to comment.


madhan ravi
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

Show 6 older comments
Mirsamir Salahov
Mirsamir Salahov on 30 May 2020
no they are named like camera standard picture names like D003892 something like this, but I can to rename them
madhan ravi
madhan ravi on 30 May 2020
Man you are complicating a simple problem.

Sign in to comment.