% Fit rate

clear;

[x,y] = textread('fig2-b.data');
npoints = 100;
xpoints = linspace(0, max(x), npoints);
  
clf;

Nmax = 5;
for N = 1:Nmax
  subplot(Nmax,1,N);
  plot(x,y, 'k.');
  parameters = [max(y) * rand(N,1); max(x) * rand(N,1)]; % random parameters
  parameters = nlinfit(x, y, 'nexponential', parameters);  
  ypoints = nexponential(parameters, xpoints);
  hold on;
  plot(xpoints, ypoints, 'r-');
  set(gca,'XTick', []);
  set(gca,'YTick', []);
  axis([0 max(x) 0 max(y)]);
  text(0, max(y)/15, sprintf('N = %d', N));
end
exportfig(gcf, 'multiple-exp-fit.eps', 'width', 4, 'height', 10, 'color', 'cmyk');
system('epstopdf multiple-exp-fit.eps');



