- converted it to accept the columns instead of the rows
- used element-wise multiplication and division operators, instead of matrix operations
Predictor and Response Variables must have same length error
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sam Mahdi
am 1 Jun. 2023
Bearbeitet: the cyclist
am 1 Jun. 2023
Hello,
I am attempting to use fitnlm, and come across an error I don't understand.
x =[p;l];
model=@(b,x)((x(1,:)+x(2,:)+b(2))-sqrt((x(1,:)+x(2,:)+b(2)).^2)-(4*x(1,:)*x(2,:)))*(b(1)/(2*x(1,:)));
beta0=[0.1,1];
for i=1:rows
y=csp(i,:)
x
size(x(1,:))
size(x(2,:))
size(y)
fitnlm(x,y,model,beta0)
end
Issue is, the x and y are the same length so I don't quite know why I'm getting this error
y =
0 0 0 0 0 0 0 0 0
x =
0.1500 0.1800 0.1900 0.2100 0.2300 0.2500 0.2600 0.2800 0.3000
1.1000 0.8800 0.7700 0.6300 0.4700 0.3700 0.2600 0.1400 0
ans =
1 9
ans =
1 9
ans =
1 9
0 Kommentare
Akzeptierte Antwort
the cyclist
am 1 Jun. 2023
Bearbeitet: the cyclist
am 1 Jun. 2023
fitnlm expects column vectors as input, not row vectors. Rows are the observations, and columns are variables.
y = [0 0 0 0 0 0 0 0 0]';
x = [0.1500 0.1800 0.1900 0.2100 0.2300 0.2500 0.2600 0.2800 0.3000;
1.1000 0.8800 0.7700 0.6300 0.4700 0.3700 0.2600 0.1400 0]';
model=@(b,x)((x(:,1)+x(:,2)+b(2))-sqrt((x(:,1)+x(:,2)+b(2)).^2)-(4*x(:,1).*x(:,2))).*(b(1)./(2.*x(:,1)));
beta0=[0.1,1];
fitnlm(x,y,model,beta0)
Note that I also did two fixes to your model definition:
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Nonlinear Regression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!