Data fit problem, 'Data must be numeric, datetime, duration or an array convertible to double.'
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Editor
le 18 Oct 2022
Commenté : Editor
le 18 Oct 2022
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)
0 commentaires
Réponse acceptée
Karen Yadira Lliguin León
le 18 Oct 2022
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 commentaires
Karen Yadira Lliguin León
le 18 Oct 2022
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)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!