function matrix_colorcode(datamatrix,rowperm,colperm,cmap)

% MATRIX_COLORCODE constructs a color representation for the values in an
% $n \times m$ matrix, DATAMATRIX.  The rows and columns of DATAMATRIX are
% permuted by ROWPERM and COLPERM, respectively.  CMAP is the input
% colormap for the representation (e.g., bone(256)).
%
% syntax:  matrix_colorcode(datamatrix,rowperm,colperm,cmap)

[n,m] = size(datamatrix);

pcolor(0.5:1:(m + 0.5), 0.5:1:(n + 0.5),[datamatrix(rowperm,colperm), zeros(n,1); [zeros(1,m), 0]]);

axis ij
colormap(cmap);
colorbar;