exponential fit

8 views (last 30 days)
johny9637
johny9637 on 21 Mar 2012
hi,i would like to fit data using a loop for every 5 points(values) which would shift(move) to one next value.
clc
format long
load C:\matlab_prog\IRC_2011_11_18_15_23_26_TEST04_charg.dat
A=IRC_2011_11_18_15_23_26_TEST04_charg
A(:,1)=[]
Z=length(A)
Y=A(1,2)
B=zeros(Z,2);
B(:,2)=[Y;]
C=A-B
B=C
D=C
B(:,1)=[]
D(:,2)=[]
loglog (B,D,'*')
hold on
X=3
O=7
%X2=4
%P=zeros(Z-X,5)
while O<Z
E=C(X:O,:)
M=E(1,2)
N=E(5,2)
G=E
H=E
G(:,1)=[]
H(:,2)=[]
H1=rot90(H)
if H1(1)~=H1(3)
X=X+1
O=O+1
loglog(G,H,'x')
hold on
s=exp2fit(G,H,1)
fun = @(s,G) s(1)+s(2)*exp(-G/s(3));
tt=linspace(M,N,5);
ff=fun(s,tt);
loglog(tt,ff,'red');
hold on
%end
else %H1(1)==H1(5)
X=X+1
O=O+1
end
%S1=ones(1,5)
%S1=S1*s(1)
%S2=ones(1,5)
%S2=S2*s(2)
%S3=ones(1,5)
%S3=S3*s(3)
%R=[tt;ff;S1;S2;S3]
%R=rot90(R)
%if X==3
%P=R(1:3,:)
%else X<Z
%P(X2,:)=R(3,:)
%X2=X2+1
end
??? Error using ==> snls at 269 lsqcurvefit cannot continue: user function is returning Inf or NaN values.
Error in ==> lsqncommon at 231 [x,FVAL,LAMBDA,JACOB,EXITFLAG,OUTPUT,msg]=...
Error in ==> lsqcurvefit at 186 [x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
Error in ==> exp2fit at 205 [s,RESNORM,RESIDUAL,EXIT]=lsqcurvefit(fun,s0,t,f,[],[],options);
Error in ==> fit2 at 35 s=exp2fit(G,H,1)

Answers (0)

Categories

Find more on Fit Postprocessing in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!