Index exceeds the number of array elements (1).

1 vue (au cours des 30 derniers jours)
Heya :)
Heya :) le 18 Sep 2020
Modifié(e) : Heya :) le 16 Oct 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;
>> ]

Réponse acceptée

KSSV
KSSV le 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 commentaire
Heya :)
Heya :) le 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;

Connectez-vous pour commenter.

Plus de réponses (1)

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

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by