Main Content

snapnow

Take snapshot of image for inclusion in published document

Syntax

Description

example

snapnow, in a file being published, takes a snapshot of the most recently generated image or plot. The snapshot appears at the end of the code section that contains the snapnow command. For more information about publishing, see Publish and Share MATLAB Code.

Outside of the context of publishing a file, MATLAB® interprets a snapnow command as a drawnow command.

Examples

collapse all

Use snapnow to capture a snapshot of an image after each iteration of a loop.

Create a file loopIterations.m with this code that runs a for loop three times and produces graphics after every iteration.

%% Scale magic Data and Display as Image
for i=1:3
    imagesc(magic(i))
end

Save and then publish the file. MATLAB displays the published file with only a snapshot of the final image.

publish('loopIterations.m')
web('html/loopIterations.html')

Add a call to the snapnow function inside the for loop.

%% Scale magic Data and Display as Image
for i=1:3
    imagesc(magic(i))
    snapnow;
end

Save and then publish the file. MATLAB displays the published file with a snapshot for each loop iteration.

publish('loopIterations.m')
web('html/loopIterations.html')

Version History

Introduced in R2008b