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

3 次查看(过去 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
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
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