Index exceeds the number of array elements (1).

1 Ansicht (letzte 30 Tage)
Heya :)
Heya :) am 18 Sep. 2020
Bearbeitet: Heya :) am 16 Okt. 2020
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;
>> ]

Akzeptierte Antwort

KSSV
KSSV am 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 Kommentar
Heya :)
Heya :) am 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;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Alan Stevens
Alan Stevens am 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);

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by