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

조회 수: 1 (최근 30일)
matlab
matlab 2020년 9월 30일
댓글: Star Strider 2020년 10월 8일
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