Error in model function using fitnlm
8 次查看(过去 30 天)
显示 更早的评论
Hello everyone!
I'm having some trouble with a code I'm working on. I need to make non linear regression of some datas I have stored using different model functions but I can't make it work.
The central part of the code is
load('Dati_3-08.dat');
f1=@(x,a) a(1)+a(2).*(x-1.1);
f2=@(x,a) a(1)+a(2).*(x-1.1)+a(3).*(x-1.1).^2;
f3=@(x,a) a(1)+a(2).*(x-1.1)+a(3).*(x-1.1).^2+a(4).*(x-1.1).^3;
f4=@(x,a) a(1).*exp(a(2).*(x-1.1).^2);
a1=randn(2,1);
a2=randn(3,1);
a3=randn(4,1);
a4=randn(2,1);
r1=fitnlm(Dati_3_08(:,1),Dati_3_08(:,2),f1,a1);
r2=fitnlm(Dati_3_08(:,1),Dati_3_08(:,2),f2,a2);
r3=fitnlm(Dati_3_08(:,1),Dati_3_08(:,2),f3,a3);
r4=fitnlm(Dati_3_08(:,1),Dati_3_08(:,2),f4,a4);
where Dati_3_08 is a 18x2 matrix.
The error I keep getting is: "MODELFUN must be a function that returns a vector of fitted values the same size as Y (18-by-1). The model function you provided returned a result that was 2-by-1."
I had the doubt the error was due to f1 being linear, but the same thing happen with f2 and the others model functions. What am I doing wrong?
Also, with f1 being linear should I change fitnlm (since it's for non linear regression) in a linear regression function or should it still work?
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!