saying that Index in position 2 exceeds array bounds (must not exceed 1) for line 7

1 次查看(过去 30 天)
data_2=data(:,1);
data_1=data(:,2);
data_=data(:,3);
stuff=data(:,4);
log= @(p,x) -(p(1)+p(2)*x(:,1)).*x(:,3).^p(3);
guess=[4 1]
log_model=fitnlm(data_2,data_,log,guess);
calc_log=feval(log_model,[data_2,data_1,data_]);
  4 个评论

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2020-9-30
There are two problems that I can see.
First, ‘data_2’ is a column vector, so it does not have a second column, and ‘x’ must br a (Nx3) matrix, not a vector, or better than that, a (Nx2) matrix of the appropriate data vectors, and change the reference to ‘x(:,2)’. That is throwing an error where you refer to ‘x(:,3)’ in your (inappropriately-named) ‘log’ function. (Please name it something such as ‘log_model’ that does not overshadow a MATLAB function!)
Second, you are estimating 3 parameters, so ‘guess’ must have a value for each one of them. Right now, it only has values for 2.
Otherwise, this call:
log_model=fitnlm(data_2,data_,log,guess);
appears to be correct.
I cannot run your code, so there could be more problems that only running it could detect.

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by