How do I use subplot and hold command simultaneously?

조회 수: 8 (최근 30일)
Blake Melling
Blake Melling 2018년 11월 9일
댓글: KSSV 2018년 11월 9일
This code works fine until I attempt to plot the bottom portion of the script. I can tell there is an issue with the way I'm using the hold command, but can't pinpoint exactly what is wrong. Any guidance on this is appreciated.
t=0:.75:9.75;
ThB=30-9.684*10^(-4).*t.^5+.02421.*t.^(4)-.1614.*t.^(3);
ThJ=20+6.1002*10^(-3).*t.^(5)-.152505.*t.^(4)+1.0167.*t.^(3);
for n=2:length(t)
vB_estimate(n)=(ThB(n)-ThB(n-1))/(t(n)-t(n-1));
vJ_estimate(n)=(ThJ(n)-ThJ(n-1))/(t(n)-t(n-1));
end
vB_actual=-5*9.684*10^(-4).*t.^(4)+4*.02421.*t.^(3)-3*.1614.*t.^(2);
vJ_actual=5*6.1002*10^(-3).*t.^(4)-4*.152505.*t.^(3)+3*1.0167.*t.^(2);
subplot(2,1,1);
plot(t,vB_estimate);
hold on;
plot(t,vB_actual);
xlabel('Time, s');
ylabel('Angular Velocity, deg/s');
title('Angular Velocity of Base Angle');
legend('Estimate','Actual');
hold off;
subplot(2,1,2);
plot(t,vJ_estimate);
hold on;
plot(t,vJ_actual);
xlabel('Time, s');
ylabel('Angular Velocity, deg/s');
title('Angular Velocity of Joint Angle');
legend('Estimate','Actual');
hold off;
vB_error=abs(vB_estimate-vB_actual);
vJ_error=abs(vJ_estimate-vJ_actual);
plot(t,vB_error);
xlabel('Time, s');
ylabel('Error of Angular Velocity Estimate, deg/s');
title('Absolute Error of Angular Velocity Estimates');
hold on;
plot(t,vJ_error);
legend('Base Angle','Joint Angle');
hold off;
  댓글 수: 5
Blake Melling
Blake Melling 2018년 11월 9일
Thank you!
KSSV
KSSV 2018년 11월 9일
Hey you need to initialize the arrays which are in loop.
vB_estimate = zeros(1,length(t)) ;
vJ_estimate = zeros(1,length(t)) ;

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by