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 个评论
采纳的回答
Asad (Mehrzad) Khoddam
2020-10-1
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!