- 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
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
the cyclist
2023-6-1
编辑:the cyclist
2023-6-1
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!