Index exceeds the number of array elements (1).

조회 수: 1 (최근 30일)
Heya :)
Heya :) 2020년 9월 18일
편집: Heya :) 2020년 10월 16일
Can anybody please help why I am getting this error. I am unable to figure out what I am doing wrong in this code.
I am getting this error [ndex exceeds the number of array elements (1).
Error in trial (line 132)
xhat(i)= d1+d2*x_rec(i-1)+d3*y_rec(i-1)+d4*x_rec(i-1)*y_rec(i-1)+d5*x_rec(i-1)^2+d6*y_rec(i-1)^2+d7*x_rec(i-1)^2*y_rec(i-1)^2+d8*x_rec(i-1)^2*y_rec(i-1)+d9*x_rec(i-1)*y_rec(i-1)^2+d10*x_rec(i-1)^3+d11*y_rec(i-1)^3+d12*x_rec(i-1)^3*y_rec(i-1)+d13*x_rec(i-1)*y_rec(i-1)^3+d14*x_rec(i-1)^3*y_rec(i-1)^2+d15*x_rec(i-1)^2*y_rec(i-1)^3+d16*x_rec(i-1)^3*y_rec(i-1)^3;
>> ]

채택된 답변

KSSV
KSSV 2020년 9월 18일
Repalce with this the for loop.
for i=2:length(x_rec)
xhat(i)= d1+d2*x_rec(i-1)+d3*y_rec(i-1)+d4*x_rec(i-1)*y_rec(i-1)+d5*x_rec(i-1)^2+d6*y_rec(i-1)^2+d7*x_rec(i-1)^2*y_rec(i-1)^2+d8*x_rec(i-1)^2*y_rec(i-1)+d9*x_rec(i-1)*y_rec(i-1)^2+d10*x_rec(i-1)^3+d11*y_rec(i-1)^3+d12*x_rec(i-1)^3*y_rec(i-1)+d13*x_rec(i-1)*y_rec(i-1)^3+d14*x_rec(i-1)^3*y_rec(i-1)^2+d15*x_rec(i-1)^2*y_rec(i-1)^3+d16*x_rec(i-1)^3*y_rec(i-1)^3;
end
  댓글 수: 1
Heya :)
Heya :) 2020년 9월 18일
Thank you for the response. Now, its giving me this error.
Unrecognized function or variable 'xhat'.
Error in trial (line 132)
PE_x(count)=PE_x(count)+(xhat(i)-x(i))^2;

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Alan Stevens
Alan Stevens 2020년 9월 18일
You should put
x_rec = zeros(1000,1);
y_rec = zeros(1000,1);
just before
x_rec(1)=x(1);
y_rec(1)=y(1);

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by