function l = mniceticks(i, j, n)
% MNICETICKS Generate a set of nice numbers for tick labels
% l = mniceticks(i, j, n) Generates a list, l, of approximately n numbers 
% between i and j using Paul Heckberts algorithm.
%
% (c) 2010 Mikkel N. Schmidt, ms@it.dk, www.mikkelschmidt.dk

r = nicenum(j-i,false);
d = nicenum(r/(n-1),true);
ni = floor(i/d)*d;
nj = ceil(j/d)*d;
l = ni:d:nj+0.5*d;

function n = nicenum(x, r)
e = floor(log10(x));
f = x/10.^e;
if r
    if f<1.5, n = 1;
    elseif f<3, n = 2;
    elseif f<7, n = 5;
    else n = 10; end;
else
    if f<=1, n = 1;
    elseif f<=2, n = 2;
    elseif f<=5, n = 5;
    else n = 10; end;
end
n = n*10^e;