function matrix_movie(datamatrix,perms,numperms,cmap)

% MATRIX_MOVIE constructs a color movie of the effects of a series
% of permutations on a proximity matrix.
% DATAMATRIX is an n by n symmetric proximity matrix; PERMS is
% a cell array containing NUMPERMS permutations; CMAP
% is the input colormap used for the representation (e.g.,
% bone(256)).

n = size(datamatrix,1);

for i = 1:numperms
    pcolor(0.5:1:(n+0.5),0.5:1:(n+0.5),[datamatrix(perms{i},perms{i}) zeros(n,1); [zeros(1,n) -1]]);
    axis ij;
    colormap(cmap);
    colorbar;
    m(i) = getframe;
end

movie(m);
