function errEN(eastErr, northErr, filePrefix, titleStr, MaxErr, Step, logScale)

eastErr  = eastErr(:);
northErr = northErr(:);

% Remove any NaNs - we should get NaN in both axis at the same time,
% just in case check both axis
i = isnan(eastErr);
eastErr(i)  = [];
northErr(i) = [];

i = isnan(northErr);
eastErr(i)  = [];
northErr(i) = [];


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Hard limit the outliers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
i = find(eastErr > MaxErr);
if(length(i) > 0)
  eastErr(i) = MaxErr-Step;
end
i = find(eastErr < -MaxErr);
if(length(i) > 0)
  eastErr(i) = MaxErr+Step;
end


i = find(northErr > MaxErr);
if(length(i) > 0)
  northErr(i) = MaxErr-Step;
end
i = find(northErr < -MaxErr);
if(length(i) > 0)
  northErr(i) = MaxErr+Step;
end


figure
dat = [eastErr,northErr];
ctrs{1} = -MaxErr:Step:MaxErr;
ctrs{2} = -MaxErr:Step:MaxErr;
if(exist('OCTAVE_VERSION', 'builtin') ~= 0)
  n1 = hist3(dat,'Ctrs',ctrs);
else
  n1 = hist3(dat,'ctrs',ctrs);
end
n1 = n1';
if(logScale)
  n1 = log10(n1);
end

xb = ctrs{1};
yb = ctrs{2};

% For octave NaN does not work in pcolor to set
% a transparent value. Therefore we'll find and remove
% all zeros. However, log10(1) = 0 so adjust slightly so
% this data does not get lost.
if(logScale)
  if(exist('OCTAVE_VERSION', 'builtin') ~= 0)
    i = find(n1 == 0);
    if(length(i) > 0)
      % log10(2) = 0.3 so set slightly lower
      n1(i) = 0.2;
    end
  end

  i = find(~isfinite(n1));
  if(length(i) > 0)
    if(exist('OCTAVE_VERSION', 'builtin') ~= 0)
      n1(i) = 0;
    else
      % In Matlab setting to NaN sets the data transparent
      n1(i) = NaN;
    end
  end
else
  i = find(~isfinite(n1) | (n1==0));
  if(length(i) > 0)
    if(exist('OCTAVE_VERSION', 'builtin') ~= 0)
      n1(i) = 0;
    else
      % In Matlab setting to NaN sets the data transparent
      n1(i) = NaN;
    end
  end
end

h = pcolor(xb,yb,n1);
set(h, 'EdgeColor', 'none');

CM = colormap('jet');
% In Matlab pcolor plots NaN as transparent. In Octave it plots the
% NaN's as the first colour in the colormap. Tweak the colormap to
% set the first colour white
if(exist('OCTAVE_VERSION', 'builtin') ~= 0)
  CM(1,1:3) = 1;
  colormap(CM);
end

xlabel('East Error [m]'); 
ylabel('North Error [m]');

grid;
h = colorbar;
if(logScale)
  if(exist('OCTAVE_VERSION', 'builtin') ~= 0)
    set(get(h,'Ylabel'),'String','log10(Number of Points)','FontSize',20,'FontName','Arial');
  else
    set(get(h,'Ylabel'),'String','log10(Number of Points)','FontSize',12,'FontName','Arial');
  end
else
  if(exist('OCTAVE_VERSION', 'builtin') ~= 0)
    set(get(h,'Ylabel'),'String','Number of Points','FontSize',20,'FontName','Arial');
  else
    set(get(h,'Ylabel'),'String','Number of Points','FontSize',12,'FontName','Arial');
  end
end

axis square
title(titleStr);

if(exist('OCTAVE_VERSION', 'builtin') ~= 0)
  print('-dpng',[filePrefix,'-ENerrPlot.png'],'-S960,720');
else
  print('-dpng',[filePrefix,'-ENerrPlot.png']);
end


