function pixgrid(n, ba)
% PIXGRID Resize figure and axes so that there is one pixel for
%         each grid point.
%   PIXGRID(N, BA)
%      N = SIZE(X) - size of the grid array
%      BA (optional, default BA = 35) - number of pixels between
%         figure boundary and axis on all sides 

  if nargin == 1, ba = 35;
  elseif nargin ~= 2,
    disp('Wrong number of input arguments in PIXGRID');
  end,
  fpos = get(gcf,'pos');  nbx = n(2)+2*ba;  nby = n(1)+2*ba;
  set(gcf,'pos',[fpos(1) fpos(2)+fpos(4)-nby nbx nby]);
  set(gca,'pos',[ba./nbx ba./nby n(2)./nbx n(1)./nby]);
  axis image;

return;
