error using plot vectors must be the same length

1 回表示 (過去 30 日間)
Heya :)
Heya :) 2020 年 10 月 1 日
回答済み: Asad (Mehrzad) Khoddam 2020 年 10 月 1 日
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
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 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by