%% Customized Plot of Simulated Response to Arbitrary Input Signal
% For this example, change time units to minutes and turn the grid on for the simulated response plot. Consider the following transfer function.

sys = tf(3,[1 2 3]);

% To compute the response of this system to an arbitrary input signal, provide lsimplot with a vector of the times t at which you want to compute the response and a vector u containing the corresponding signal values. For instance, plot the system response to a ramping step signal that starts at 0 at time t = 0, ramps from 0 at t = 1 to 1 at t = 2, and then holds steady at 1. Define t and compute the values of u.

t = 0:0.04:8;
u = max(0,min(t-1,1));

% Use lsimplot plot the system response to the signal with a plot handle h.

h = lsimplot(sys,u,t);

% The plot shows the applied input (u,t) in gray and the system response in blue.
%
% Use the plot handle to change the time units to minutes and to turn the grid on. To do so, edit properties of the plot handle, h using setoptions.

setoptions(h,'TimeUnits','minutes','Grid','on')

% The plot automatically updates when you call setoptions.
%
% Alternatively, you can also use the timeoptions command to specify the required plot options. First, create an options set based on the toolbox preferences.

plotoptions = timeoptions('cstprefs');

% Change properties of the options set by setting the time units to minutes and enabling the grid.

plotoptions.TimeUnits = 'minutes';
plotoptions.Grid = 'on';
lsimplot(sys,u,t,plotoptions);

% Copyright 2021 The MathWorks, Inc.