error using plot vectors must be the same length

1 次查看(过去 30 天)
Why i am getting this error in plot (Data, hx,) and how to fix it?
This is my code
for i=2:test_points
x_rec(i)=c1+c2*x_rec(i-1)+c3*hx(i-1)+c4*x_rec(i-1)*hx(i-1)+c5*x_rec(i-1)^2+c6*hx(i-1)^2+c7*x_rec(i-1)^2*hx(i-1)^2;
hx(i)=d1+d2*x_rec(i-1)+d3*hx(i-1)+d4*x_rec(i-1)*hx(i-1)+d5*x_rec(i-1)^2+d6*hx(i-1)^2+d7*x_rec(i-1)^2*hx(i-1)^2;
x_real(i)=x(start_point+i-1);
error=error+(x_rec(i)-x_real(i))^2;
DN=DN+x_real(i)^2;
end
Error_x(count)=sqrt(error)/sqrt(DN);
end
figure
hold on
plot (Data,Error_x,'s-r')
plot (Data,hx,'s-b')
This is the error
Vectors must be the same length.
Error in PE_HT (line 136)
plot (Data,hx,'s-b')
  2 个评论
dpb
dpb 2020-10-1
Too much undefined in the code snippet for us to tell...
KSSV
KSSV 2020-10-1
The error is clear....diemnsions of Data and hx are not same. Check their sizes.

请先登录,再进行评论。

采纳的回答

Asad (Mehrzad) Khoddam
try to use this line of code inside the loop. For now, the code returns a single point for error;
for i=2:test_points
x_rec(i)=c1+c2*x_rec(i-1)+c3*hx(i-1)+c4*x_rec(i-1)*hx(i-1)+c5*x_rec(i-1)^2+c6*hx(i-1)^2+c7*x_rec(i-1)^2*hx(i-1)^2;
hx(i)=d1+d2*x_rec(i-1)+d3*hx(i-1)+d4*x_rec(i-1)*hx(i-1)+d5*x_rec(i-1)^2+d6*hx(i-1)^2+d7*x_rec(i-1)^2*hx(i-1)^2;
x_real(i)=x(start_point+i-1);
error=error+(x_rec(i)-x_real(i))^2;
DN=DN+x_real(i)^2;
Error_x(i)=sqrt(error)/sqrt(DN);
end
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by