필터 지우기
필터 지우기

Nlinfit error with func2str

조회 수: 1 (최근 30일)
Michael Lherbette
Michael Lherbette 2015년 8월 11일
댓글: Michael Lherbette 2015년 8월 12일
Hello,
I am trying to fit a curve using this function: t is the time vector, x the force measurement, d0 and nu are constants. I want to extract Er, tau1 and tau2.
function [Er,tau1,tau2] = viscoelasticcone(t,x,d0,nu)
fitfunctionconical=sprintf('Er*2*tan(35*pi/180)/(pi*(1-%d^2))*%d^2*(1+(tau1-tau2)/tau2*exp(-t/tau2))',nu,d0);
ftconical=fittype( fitfunctionconical, 'independent', 't', 'dependent', 'F');
[fitresult,R,~,CovB,MSE] = nlinfit(t,x, ftconical,[1e3 0.001 0.001]);
fit=ftconical(fitresult,t);
[Ypred,delta] = nlpredci(ftconical,t,fitresult,R,'Covar',CovB,'MSE',MSE,'SimOpt','on');
confidence{k}=delta;
lower = Ypred - delta;
upper = Ypred + delta;
end
If I use this function however, i get the following error:
Undefined function 'func2str' for input arguments of type 'fittype'.
Error in nlinfit (line 204)
m = message('stats:nlinfit:ModelFunctionError',func2str(model));
Any help ?
Michael

채택된 답변

Walter Roberson
Walter Roberson 2015년 8월 11일
You need to call fit() on fit objects returned from fittype(), not nlinfit()
  댓글 수: 2
Michael Lherbette
Michael Lherbette 2015년 8월 12일
Hello Walter,
What about the nlinfit ?
I use fit with option equal to NonLinearLeastSquares but I have a real trouble with the fitting.
s = fitoptions('Method','NonlinearLeastSquares');
fitfunctionconical=sprintf('Er*2*tan(35*pi/180)/(pi*(1-%d))*%d^2*(1+(tau1-tau2)/tau2*exp(-t/tau2))',nu,d0);
ftconical=fittype( fitfunctionconical, 'independent', 't', 'dependent', 'F','coefficients',{'Er','tau1','tau2'},'option',s);
fitresult = fit(t',x, ftconical);
coeffvals = coeffvalues(fitresult);
I get wrong values for the coefficients and the curve is not at all fitted.
Michael Lherbette
Michael Lherbette 2015년 8월 12일
All right,
Here my final code:
ftVisco= @(b, t) b(1)*2*tan(35*pi/180)/(pi*(1-nu))*d0^2*(1+(b(2)-b(3))/b(3).*exp(-t./b(3)));
[fitresultnlinfit, R,~,CovB,MSE,Errorinfo] = nlinfit(t',x, ftVisco, [1e3 0.001 0.001]);
fitresultnlinfit
[Ypred,delta] = nlpredci(ftVisco,t',fitresultnlinfit,R,'Covar',CovB,'MSE',MSE);
confidence=delta;
lower = Ypred - delta;
upper = Ypred + delta;
It seems to work well.
Thank you Walter for pointing me out that we can't use fittype for nlinfit.
Cheers

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fit Postprocessing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by