Data fit problem, 'Data must be numeric, datetime, duration or an array convertible to double.'

조회 수: 7 (최근 30일)
Dear all. I am trying to fit my model to data and determine the confidence interval for the fitted parameters. However, when I run my code, I get an error 'Data must be numeric, datetime, duration or an array convertible to double'. I am sure the problem is that "fittedmdl" is an object. I have tried to search related questions online but still I can't seem to get round my problem. Any insight into this will greatly be appreciated. Below is my code.
close all; clear; clc;
x=[100; 101.0932476; 97.12643678; 97.51209399; 96.89011748; 74.54219031; 84.76551121; 58.28584719; 50.17251294; 51.58143659; 48.325];
t=[0; 24; 24; 24; 24; 48; 48; 48; 72; 72; 72;];
fo = fitoptions('Method','NonlinearLeastSquares',...
'Lower',[0,0,0,0],...
'Upper',[Inf,max(t)],...
'StartPoint',[20 0.1 0.1 0.1]);
fittedmdl = fittype('100*A*exp((-C.*(1-exp(-lambda.*t))/lambda)-(D*(exp(-lambda.*t)-1+lambda.*t)/lambda^2))', ...
'independent',{'t'},'coefficients',{ 'A', 'C', 'D', 'lambda'},'options',fo)
[curve2,gof2] = fit(t,x,fittedmdl)
H = plot(fittedmdl,t,x); H(1).MarkerSize = 20; H(1).Color = 'm'; H(2).Color='k';H(2).LineWidth=2;
hold on
xint = linspace(min(t),max(t),1000);
CIF = predint(fittedmdl,xint,0.95,'Functional'); % 95% CI for the fitted curve
plot(t,x,'.m', MarkerSize=20)
hold on
plot(xint,CIF,'-b',linewidth=1)

채택된 답변

Karen Yadira Lliguin León
Karen Yadira Lliguin León 2022년 10월 18일
you need to use 'fit' (https://es.mathworks.com/help/curvefit/fit.html) first and then you are able to plot the fitobject, something like this:
myfit = fit(x,t,fittedmdl)
H = plot(myfit,t,x);
  댓글 수: 3
Karen Yadira Lliguin León
Karen Yadira Lliguin León 2022년 10월 18일
prrdint (https://es.mathworks.com/help/curvefit/cfit.predint.html) need a fitobject, so in your case 'myfit'.
Hope this works for you!
CIF = predint(myfit,xint,0.95,'Functional'); % 95% CI for the fitted curve
plot(t,x,'.m', 'MarkerSize',20)
hold on
plot(xint,CIF,'-b','linewidth',1)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by