How to add image in MATLAB GUI?

image, matlab

Solution

I'm not totally sure of what you want to do (specifically what type of images you are trying to display), but here's some sample code that may do what you want:

image1 = imread('cameraman.tif');  % Load a test image
image2 = imread('circles.png');    % Load another test image

hAxes = gca;  % Get a handle to the current axes

for iLoop = 1:5,  % Loop five times
  imshow(image1,'Parent',hAxes);
  pause(1);
  imshow(image2,'Parent',hAxes);
  pause(1);
end

I used the general function IMSHOW, but this sometimes changes other properties of the figure/axes and that may not be to your liking (since you mention adding this to an existing GUI). You may want to use the IMAGE function instead. Also, instead of the for loop you could use a while loop that stops switching images when a condition is met (such as a button press).

Problem

I want to switch back and forth between two images, like blinking: 1 second for the first image and one second for second image.

Original source