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!