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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by