Index exceeds the number of array elements (1).

1 view (last 30 days)
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;
>> ]

Accepted Answer

KSSV
KSSV on 18 Sep 2020
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 Comment
Heya :)
Heya :) on 18 Sep 2020
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;

Sign in to comment.

More Answers (1)

Alan Stevens
Alan Stevens on 18 Sep 2020
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);

Community Treasure Hunt

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

Start Hunting!