stepplot: Add curve to subplot of step response

조회 수: 5 (최근 30일)
Ced
Ced 2015년 11월 2일
댓글: Ced 2015년 11월 5일
Hi
I have a system with 1 input and 3 outputs for which I visualize the step response using stepplot, which returns a plot handle. However, I don't understand the plot handle object it returns.
What I would like to do is the following:
Create a step response (resulting in 3 "subplots"), and then manually plot another curve in the three subplots for comparison.
So, something like this:
% plot this dummy system with stepplot
A = -10;
B = 1;
C = [ 5 2 1 ]';
s = tf('s');
sys = C*inv(s-A)*B;
% have some other dummy plot I also want to add for comparison
t = 0:0.01:1;
y1 = 0.5*(1-exp(-10*t));
y2 = 0.2*(1-exp(-10*t));
y3 = 0.1*(1-exp(-10*t));
% stepplot
figure(1)
handle = stepplot(sys);
% overlay other plots (this is the part I cannot figure out)
plot(handle(1),y1,'LineStyle','--')
plot(handle(2),y2,'LineStyle','--')
plot(handle(3),y3,'LineStyle','--')
Thanks!

채택된 답변

Tushar Sinha
Tushar Sinha 2015년 11월 4일
Hi Ced,
You can do the manual plotting of other curves on the subplots by making use of the "getaxes" property of the handle object returned by "stepplot". Please make sure that the overlay values are within the range of the x,y axis limits of the original subplots. Here is how you can achieve this programmatically:
% plot this dummy system with stepplot
A = -10;
B = 1;
C = [ 5 2 1 ]';
s = tf('s');
sys = C*inv(s-A)*B;
% have some other dummy plot I also want to add for comparison
t = 0:0.01:1;
y1 = 0.5*(1-exp(-10*t));
y2 = 0.2*(1-exp(-10*t));
y3 = 0.1*(1-exp(-10*t));
% stepplot
figure(1)
handle = stepplot(sys);
hold all;
AxArray = handle.getaxes;
x=0.1:0.1:0.9
y = 0.2*ones(size(x));
plot(AxArray(1),x,y,'r','LineStyle','--');
plot(AxArray(2),x,y,'r','LineStyle','--');
plot(AxArray(3),x,y,'r','LineStyle','--');
I hope this helps answer your question.
Thanks,
Tushar
  댓글 수: 1
Ced
Ced 2015년 11월 5일
Just what I was looking for, thanks!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by