How do I use subplot and hold command simultaneously?
이전 댓글 표시
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
Walter Roberson
2018년 11월 9일
When you get to
plot(t,vB_error);
The current axes is 212, but you turned hold off already, so this new plot() erases what you just drew in the subplot.
Blake Melling
2018년 11월 9일
Cris LaPierre
2018년 11월 9일
place a figure() command prior to the plot command.
figure()
plot(t_vB_error)
Blake Melling
2018년 11월 9일
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개)
카테고리
도움말 센터 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!