www.gusucode.com > control 案例程序 matlab源码代码 > control/UpdateSystemDataInResponsePlotExample.m

    %% Update System Data in Response Plot
% Replace step response data in an existing plot with data computed from a different
% dynamic system model. 
%%
% Suppose you have a plant model and pure integrator controller that you
% designed for that plant. Plot the step responses of the plant and the
% closed-loop system.

% Copyright 2015 The MathWorks, Inc.

w = 2;
zeta = 0.5;
G = tf(w^2,[1,2*zeta*w,w^2]);

C1 = pid(0,0.621);
CL1 = feedback(G*C1,1);

h = stepplot(G,CL1);
%%
% |h| is the plot handle that identifies the plot created by |stepplot|. In
% this figure, |G| is used to compute the first response, and |CL1| is used to
% compute the second response. This ordering corresponds to the order of
% inputs to |stepplot|.
%%
% Suppose you also have a PID controller design that you want to analyze.
% Create a model of the closed-loop system using this alternate controller.
C2 = pid(2,2.6,0.4,0.002);
CL2 = feedback(G*C2,1);
%%
% Update the step plot to display the second closed-loop system instead of
% the first. The closed-loop system is the second response in the plot, so
% specify the index value 2.
updateSystem(h,CL2,2);
%%
% The |updateSystem| command replaces the system used to compute the second
% response displayed in the plot. Instead of displaying response data
% derived from |CL1|, the plot now shows data derived from |CL2|.
%
%%
% When you build a GUI that displays a response plot, use |updateSystem| in
% GUI control callbacks to cause those GUI controls to update the response
% plot.  For an example showing how to implement such a GUI control, see
% <docid:control_ug.bt3gc1u>.