fitSingleRamp.m 973 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. function fv=fitSingle(globalPar, par, cax)
  2. %par is a nfunc x npar matrix of coefficients
  3. %globalPar is a row vector of global coefficients
  4. %cax is a column vector of time instances
  5. %cay are the function values
  6. %oneVector=ones(1,size(cax,1));%column vector
  7. A=globalPar(1);
  8. tau=globalPar(2);
  9. t0=globalPar(5);
  10. t1=globalPar(6);
  11. k1=par(1);
  12. B=par(2);
  13. k2=par(3);
  14. kt=k1./(1/tau-k2);
  15. e0=exp(-(cax-t1)/tau);
  16. ek=exp(-(cax-t1).*k2);
  17. ek1=(1-exp(-k2.*(cax-t0)))./(k2*(t1-t0));
  18. fk1=(1-exp(-k2*(t1-t0)))./(k2*(t1-t0));
  19. fr1=k1./k2.*(1-fk1);
  20. B1=1-B;
  21. dt=(cax-t0)/(t1-t0);
  22. if k2==1/tau
  23. r0=k1*(cax-t1).*e0;
  24. else
  25. r0=kt*(ek-e0);
  26. fv=zeros(size(cax));
  27. sel=cax>t0 & cax<=t1;
  28. fv(sel)=B*dt(sel)+B1*k1/k2*(dt(sel)-ek1(sel));
  29. sel=cax>t1;
  30. fv(sel)=B*e0(sel)+B1*(fr1+r0(sel));
  31. fv=fv*A;
  32. end
  33. %par=ones(2,