% First use "File/import data" to read in X:\900225. MARS
% PROJECT\Project.Documents\02.System.Engineering\Test Results\Filled
% testing, August 2006\Aug17Regression.xls
% Make sure myfit.m is in work directory

clear
data = xlsread('X:\900225. MARS PROJECT\Project.Documents\02.System.Engineering\Test Results\Filled testing, August 2006\Aug17Regression.xls');
data = data';

t = data(2,6:650);
tPM = data(2,660:1170);
tEst = 0:.001:.15;
tPMEst = .14:.001:.25;

hold off
if 1 == 2
  initABCEst=[1 1 25];
  options = optimset('Display','final');
  input('processing AM data (hit enter to continue)');
  for i=1:6
    temp(i,:) = data(i+2,6:650);
    ABC(i,:) = fminsearch(@myFit,initABCEst,options,t,temp(i,:));
    finalTemp(i) = ABC(i,1) + ABC(i,3);
    tempEst(i,:) = ABC(i,1) * (1 - exp(-ABC(i,2) * tEst)) + ABC(i,3);
    plot(t,temp(i,:),tEst,tempEst(i,:))
    if i == 1
      hold
    end
  end
end

hold off
if 1 == 1
  initABCEst=[1 1 25];
  options = optimset('Display','final','MaxFunEvals',2000,'TolX',.1);
  input('processing PM data (hit enter to continue)');
  for i=1:6
    tempPM(i,:) = data(i+2,660:1170);
    ABCPM(i,:) = fminsearch(@myFit,initABCEst,options,tPM,tempPM(i,:));
    finalTempPM(i) = ABCPM(i,1) + ABCPM(i,3);
    tempPMEst(i,:) = ABCPM(i,1) * (1 - exp(-ABCPM(i,2) * tPMEst)) + ABCPM(i,3);
    intABCEst = [ABCPM(i,1) ABCPM(i,2) ABCPM(i,3)];
    plot(tPM,tempPM(i,:),tPMEst,tempPMEst(i,:))
    if i == 1
      hold
    end
  end
end

