- 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
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
the cyclist
il 1 Giu 2023
Modificato: the cyclist
il 1 Giu 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 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!