Force snapshot of image for inclusion in published document
The snapnow command forces a snapshot of the image or plot that the code has most recently generated for presentation in a published document. The output appears in the published document at the end of the cell that contains the snapnow command. When used outside the context of publishing a file, snapnow has the same behavior as drawnow. That is, if you run a file that contains the snapnow command, the MATLAB® software interprets it as though it were a drawnow command.
This example demonstrates the difference between publishing code that contains the snapnow command and running that code. The first image shows the results of publishing the code and the second image shows the results of running the code.
Suppose you have a file that contains the following code:
%% Scale magic Data and %% Display as Image: for i=1:3 imagesc(magic(i)) snapnow end
When you publish the code to HTML, the published document contains a title, a table of contents, the commented text, the code, and each of the three images produced by the for loop. (In the published document shown, the size of the images have been reduced.)
When you run the code, a single Figure window opens and MATLAB updates the image within this window as it evaluates each iteration of the for loop. Each successive image replaces the one that preceded it, so that the Figure window appears as follows when the code evaluation completes.