display an image for 5 seconds in matlab

main.m
% Read the image and display it
img = imread('image.jpg');
imshow(img);

% Set a timer for 5 seconds
t = timer('TimerFcn', '','StartDelay',5);
start(t);

% Pause for 5 seconds
pause(5);

% Delete the timer and close the image
stop(t);
delete(t);
close;
253 chars
16 lines

In this code, we start by reading an image and displaying it using the imshow function. Then, we create a timer object t that executes the empty TimerFcn after a StartDelay of 5 seconds. We start the timer using start(t) and pause the function for 5 seconds using the pause function. After the pause, we stop and delete the timer and close the image window. This code will display the image for 5 seconds before closing it.

gistlibby LogSnag