If you want to make a topology optimization movie, simply follow this tutorial
In some designs, some elements may be desired to be solid or void (active or passive). A $latex \texttt{nely} \times \texttt{nelx}\times \texttt{nelz}$ matrix with ones at elements desired to be solid, and a $latex \texttt{nely}\times \texttt{nelx}\times \texttt{nelz}$ matrix with zeros at elements desired to be void can be added to the program.

[expand title="Step.1: Save iteration history" expanded="true" tag="h5"]

Add the following lines after line 94

[matlab firstline="95"]
% SAVE HISTORY
save(['xPhys_it',num2str(loop,'%03d'),'.mat'], 'xPhys');
[/matlab]

It should looks like this:

[matlab firstline="93" highlight="95-96,"]
% PLOT DENSITIES
if displayflag, clf; display_3D(xPhys); end %#ok<UNRCH>
% SAVE HISTORY
save(['xPhys_it',num2str(loop,'%03d'),'.mat'], 'xPhys');
[/matlab]

[/expand]

[expand title="Step.2: Save the doMovie.m under the save directory as top3d.m" expanded="true" tag="h5"]

[matlab]
function doMovie
% Make a topology optimizatin movie
% By K. Liu

% cutoffL allow smooth animation from 1 to 50 iterations.
% change 0.5 to the desired element density cutoff value
% change smaller 50 to allow faster animation, larger 50 to allow slower animation
cutoffL = linspace(0,0.5,50);

% Do Movie
i = 0;
while (1)
i = i + 1;
filename = ['xPhys_it',num2str(i,'%03d'),'.mat'];
if exist(filename,'file') == 0
break;
end
load(filename)
if i <= length(cutoffL)
cutoff = cutoffL(i);
else
cutoff = max(cutoffL);
end

plot_3d(xPhys, cutoff, 1, [0.7 0.7 0.7]);
drawnow
mov(i) = getframe(gcf); %#ok&lt;AGROW&gt;

end

movie2avi(mov, 'myTopopt.avi'); %#ok<MOVIE2>
end

% DISPLAY 3D TOPOLOGY (ISO-VIEW)
% Special thanks to Tomas Zegard (UIUC) for quick plot function
% Code snippets from Top3d (top3dapp.com)
% Top3d - An efficient 3D topology optimization program written in MATLAB
% By K. Liu and A. Tovar
% http://www.top3dapp.com
function [p] = plot_3d(x, cutoff, Alpha, fcolor)

if nargin < 4, fcolor = 'r'; end

[nely,nelx,nelz] = size(x);
aux = zeros(nely+2,nelx+2,nelz+2);
aux(2:end-1,2:end-1,2:end-1) = x;

cla, hold on, view(30,30), rotate3d on, axis equal, axis([0 nelx 0 nelz 0 nely]), box
set(gca,'YDir','reverse','ZDir','reverse','ZtickLabel',flipud(get(gca,'Ztick')'));
% set(gcf,'MenuBar','none','ToolBar','none')
[X,Y,Z] = meshgrid(0:nelx+1,0:nely+1,0:nelz+1);
p = patch(isosurface(X-0.5,Z-0.5,Y-0.5,aux,cutoff),...
'FaceColor',fcolor,'EdgeColor','none','FaceAlpha',Alpha);
camlight, lighting gouraud;
axis off; box off; set(gcf, 'color', [1 1 1])
drawnow
end
[/matlab]

[/expand]

[expand title="Step.3: Run the program" expanded="true" tag="h5"]

After running the topology optimization, run the doMovie program

[matlab light="true"]doMovie[/matlab]

[/expand]

Here are some movies we made using this program

https://vimeo.com/107920230
https://vimeo.com/107920144
https://vimeo.com/107920140
https://vimeo.com/107920138
https://vimeo.com/107920136
https://vimeo.com/107920135