function h = display_pat( Pats, nrow )
%
% display_pat -- display the loaded patterns of ETL1
%
% Usage:
%    h = display_pat( Pats )
%     
%    Pats: Loaded patterns by LoadPat() MEX function
%    nrow: number of patterns in horizontal axis

figure( 1 );

[W H P] = size( Pats );

m = nrow;
n = floor( P / nrow );
if( mod( P, nrow ) > 0 ), n=n+1, end

pmax = max( Pats(:) )
mgn = 4;     % margin size

ary = -ones( mgn + m * (W+mgn), mgn + n * (H+mgn) );

k=1;
for i=1:m
  for j=1:n
    clim = max(max(abs(Pats(:,:,k))));
    ary( mgn+(i-1)*(W+mgn)+[1:W], mgn+(j-1)*(H+mgn)+[1:H])=...
	Pats(:,:,k)';
    k = k+1;
  end
end
colormap( bone );
h = imagesc( ary, 'EraseMode', 'none', [-1 pmax]);
axis image off
 

