stepplot
Plot step response of dynamic system
Description
The stepplot
function plots the step response of a dynamic system model and returns a
StepPlot
chart object. To customize the plot, modify the properties of the
chart object using dot notation. For more information, see Customize Linear Analysis Plots at Command Line (Control System Toolbox).
To obtain step response data, use step
.
Creation
Syntax
Description
plots the step response of the dynamic system model sp
= stepplot(sys
)sys
and returns
the corresponding chart object.
simulates the response for the time steps specified by sp
= stepplot(___,t
)t
. To define
the time steps, you can specify:
The final simulation time using a scalar value.
The initial and final simulation times using a two-element vector. (since R2023b)
All the time steps using a vector.
specifies additional options for computing the step response, such as the step amplitude
(dU) or input offset (U). Use sp
= stepplot(___,config
)RespConfig
to create config
.
plots the step response with the plotting options specified in
sp
= stepplot(___,plotoptions
)plotoptions
. Settings you specify in
plotoptions
override the plotting preferences for the current
MATLAB® session. This syntax is useful when you want to write a script to generate
multiple plots that look the same regardless of the local preferences.
plots the step response in the specified parent graphics container, such as a
sp
= stepplot(parent
,___)Figure
or TiledChartLayout
, and sets the
Parent
property. Use this syntax when you want to create a plot
in a specified open figure or when creating apps in App Designer.
Input Arguments
sys
— Dynamic system
dynamic system model | model array
Dynamic system, specified as a SISO or MIMO dynamic system model or array of dynamic system models. Dynamic systems that you can use include:
Continuous-time or discrete-time numeric LTI models, such as
tf
,zpk
, orss
models.Generalized or uncertain LTI models such as
genss
oruss
models. (Using uncertain models requires Robust Control Toolbox™ software.)For tunable control design blocks, the function evaluates the model at its current value for both plotting and returning response data.
For uncertain control design blocks, the function plots the nominal value and random samples of the model. When you use output arguments, the function returns response data for the nominal model only.
Sparse state-space models such as
sparss
andmechss
models.Identified LTI models, such as
idtf
,idss
, oridproc
models. For such models, the function can also plot confidence intervals and return standard deviations of the frequency response. See Step Responses of Identified Models with Confidence Regions.Linear time-varying (
ltvss
(Control System Toolbox)) and linear parameter-varying (lpvss
(Control System Toolbox)) models.
This function does not support frequency-response data models such as
frd
, genfrd
, or idfrd
models.
If sys
is an array of models, the function plots the responses of all models in the array on the same axes. See Step Response of Systems in a Model Array.
LineSpec
— Line style, marker, and color
string | character vector
Line style, marker, and color, specified as a string or character vector containing symbols. The symbols can appear in any order. You do not need to specify all three characteristics (line style, marker, and color). For example, if you omit the line style and specify the marker, then the plot shows only the marker and no line.
Example: '--or'
is a red dashed line with circle markers
Line Style | Description |
---|---|
"-" | Solid line |
"--" | Dashed line |
":" | Dotted line |
"-." | Dash-dotted line |
Marker | Description |
---|---|
"o" | Circle |
"+" | Plus sign |
"*" | Asterisk |
"." | Point |
"x" | Cross |
"_" | Horizontal line |
"|" | Vertical line |
"s" | Square |
"d" | Diamond |
"^" | Upward-pointing triangle |
"v" | Downward-pointing triangle |
">" | Right-pointing triangle |
"<" | Left-pointing triangle |
"p" | Pentagram |
"h" | Hexagram |
Color | Description |
---|---|
"r" | red |
"g" | green |
"b" | blue |
"c" | cyan |
"m" | magenta |
"y" | yellow |
"k" | black |
"w" | white |
t
— Time steps
positive scalar | two-element vector | vector | []
Time steps at which to compute the response, specified as one of the following:
Positive scalar
tFinal
— Compute the response fromt = 0
tot = tFinal
.Two-element vector
[t0 tFinal]
— Compute the response fromt = t0
tot = tFinal
. (since R2023b)Vector
Ti:dt:Tf
— Compute the response for the time points specified int
.For continuous-time systems,
dt
is the sample time of a discrete approximation to the continuous system.For discrete-time systems with a specified sample time,
dt
must match the sample time propertyTs
ofsys
.For discrete-time systems with an unspecified sample time (
Ts = -1
),dt
must be1
.
[]
— Automatically select time values based on system dynamics.
When you specify a time range using either tFinal
or [t0 tFinal]
:
For continuous-time systems, the function automatically determines the size of the time step and number of points based on the system dynamics.
For discrete-time systems with a specified sample time, the function uses the sample time of
sys
as the step size.For discrete-time systems with unspecified sample time (
Ts = -1
), the function interpretstFinal
as the number of sampling periods to simulate with a sample time of 1 second.
Express t
using the time units specified in the
TimeUnit
property of sys
.
If you specified a step delay td
using config
, the
function applies the step at t = t0+td
.
p
— LPV model parameter trajectory
matrix | function handle
Parameter trajectory of the LPV model, specified as a matrix or a function handle.
For exogenous or explicit trajectories, specify
p
as a matrix with dimensions N-by-Np, where N is the number of time samples and Np is the number of parameters.Thus, the row vector
p(i,:)
contains the parameter values at the ith time step.For endogenous or implicit trajectories, specify
p
as a function handle of the form p = F(t,x,u) in continuous time and p = F(k,x,u) in discrete time that gives parameters as a function of time t or time sample k, state x, and input u.This option is useful when you want to simulate quasi-LPV models. For an example, see Step Response of LPV Model.
config
— Response configuration
RespConfig
object
Configuration of the applied signal, specified as a RespConfig
object. By default, step
applies
an input that goes from 0 to 1 at time t = 0
. Use this input
argument to change the configuration of the step input. See Response to Custom Step Input for an example.
For lpvss
(Control System Toolbox) and
ltvss
(Control System Toolbox)
models with offsets
(x0(t),u0(t)),
you can use RespConfig
to define the input relative to
u0(t,p)
and initialize the simulation with the state
x0(t,p).
plotoptions
— Time response plot options
timeoptions
object
Time response plot options, specified as a timeoptions
(Control System Toolbox) object. You can use these options to customize the plot appearance. Settings you specify in plotoptions
override the preference settings for the current MATLAB session.
parent
— Parent container
Figure
object (default) | TiledChartLayout
object | UIFigure
object | UIGridLayout
object | UIPanel
object | UITab
object
Parent container of the chart, specified as one of the following objects:
Figure
TiledChartLayout
UIFigure
UIGridLayout
UIPanel
UITab
Properties
Note
The properties listed here are only a subset. For a complete list, see StepPlot Properties (Control System Toolbox).
Responses
— Model responses
StepResponse
object | array of StepResponse
objects
Model responses, specified as an StepResponse
object or an array of such objects. Use this property to modify the dynamic system model or appearance for each response in the plot. Each StepResponse
object has the following fields.
SourceData
— Source data
structure
Source data for the response, specified as a structure with the following fields.
Model
— Dynamic system
dynamic system model | model array
Dynamic system, specified as a SISO or MIMO dynamic system model or array of dynamic system models.
When you initially create a plot, Model
matches the value you specify for sys
.
TimeSpec
— Time values
scalar | vector | []
Time steps at which to compute the response, specified as one of the following:
Positive scalar
tFinal
— Compute the response fromt = 0
tot = tFinal
.Two-element vector
[t0 tFinal]
— Compute the response fromt = t0
tot = tFinal
. (since R2023b)Vector
Ti:dt:Tf
— Compute the response for the time points specified int
.For continuous-time systems,
dt
is the sample time of a discrete approximation to the continuous system.For discrete-time systems with a specified sample time,
dt
must match the sample time propertyTs
ofsys
.For discrete-time systems with an unspecified sample time (
Ts = -1
),dt
must be1
.
[]
— Automatically select time values based on system dynamics.
When you specify a time range using either tFinal
or [t0 tFinal]
:
For continuous-time systems, the function automatically determines the size of the time step and number of points based on the system dynamics.
For discrete-time systems with a specified sample time, the function uses the sample time of
sys
as the step size.For discrete-time systems with unspecified sample time (
Ts = -1
), the function interpretstFinal
as the number of sampling periods to simulate with a sample time of 1 second.
Express t
using the time units specified in the
TimeUnit
property of sys
.
If you specified a step delay td
using config
, the
function applies the step at t = t0+td
.
Config
— Response configuration options
RespConfig
object
Response configuration options, specified as a RespConfig
object.
Name
— Response name
string | character vector
Response name, specified as a string or character vector and stored as a string.
Visible
— Response visibility
"on"
(default) | on/off logical value
Response visibility, specified as one of the following logical on/off values:
"on"
,1
, ortrue
— Display the response in the plot."off"
,0
, orfalse
— Do not display the response in the plot.
The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
LegendDisplay
— Option to list response in legend
"on"
(default) | on/off logical value
Option to list response in legend, specified as one of the following logical on/off values:
"on"
,1
, ortrue
— List the response in the legend."off"
,0
, orfalse
— Do not list the response in the legend.
The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
MarkerStyle
— Marker style
"none"
| "o"
| "+"
| "*"
| "."
| ...
Marker style, specified as one of the following values.
Marker | Description |
---|---|
"none" | No marker |
"o" | Circle |
"+" | Plus sign |
"*" | Asterisk |
"." | Point |
"x" | Cross |
"_" | Horizontal line |
"|" | Vertical line |
"s" | Square |
"d" | Diamond |
"^" | Upward-pointing triangle |
"v" | Downward-pointing triangle |
">" | Right-pointing triangle |
"<" | Left-pointing triangle |
"p" | Pentagram |
"h" | Hexagram |
Color
— Plot color
RGB triplet | hexadecimal color code | color name
Plot color, specified as an RGB triplet or a hexadecimal color code and stored as an RGB triplet.
Alternatively, you can specify some common colors by name. The following table lists these colors and their corresponding RGB triplets and hexadecimal color codes.
Color Name | RGB Triplet | Hexadecimal Color Code |
---|---|---|
| [1 0 0] | #FF0000 |
| [0 1 0] | #00FF00 |
| [0 0 1] | #0000FF |
| [0 1 1] | #00FFFF |
| [1 0 1] | #FF00FF |
| [1 1 0] | #FFFF00 |
| [0 0 0] | #000000 |
| [1 1 1] | #FFFFFF |
LineStyle
— Line style
"-"
| "--"
| ":"
| "-."
Line style, specified as one of the following values.
Line Style | Description |
---|---|
"-" | Solid line |
"--" | Dashed line |
":" | Dotted line |
"-." | Dash-dotted line |
MarkerSize
— Marker size
positive scalar
Marker size, specified as a positive scalar.
LineWidth
— Line width
positive scalar
Line width, specified as a positive scalar.
Characteristics
— Response characteristics
CharacteristicsManager
object
Response characteristics to display in the plot, specified as a
CharacteristicsManager
object with the following properties.
PeakResponse
— Peak response
CharacteristicOption
object
Peak response, specified as a CharacteristicOption
object with the following
property.
Visible
— Peak response visibility
"off"
(default) | on/off logical value
Peak response visibility, specified as one of the following logical on/off values:
"on"
,1
, ortrue
— Display the peak response."off"
,0
, orfalse
— Do not display the peak response.
The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
RiseTime
— Rise time
CharacteristicOption
object
Rise time, specified as a CharacteristicOption
object with the following
fields.
Limits
— Rise time range limits
[0.1 0.9]
(default) | two-element vector
Rise time range limits, specified as a two-element vector of the form [Rmax Rmin]
, where Rmin
and Rmx
are scalar values between 0 and 1 and Rmin
is less than Rmax
. For example, to measure the time it takes for the response to rise from 5% to 95% of the way from the initial to final value, set the limits to [0.05 0.95]
.
Visible
— Rise time visibility
"off"
(default) | on/off logical value
Rise time visibility, specified as one of the following logical on/off values:
"on"
,1
, ortrue
— Display the peak response."off"
,0
, orfalse
— Do not display the peak response.
The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
SettlingTime
— Settling time
CharacteristicOption
object
Settling time, specified as a CharacteristicOption
object with the following
properties.
Threshold
— Threshold for detecting steady state
0.02
(default) | scalar value between 0 and 1
Threshold for detecting steady state, specified as a scalar value between 0 and 1. For example, to measure when the response remains with 5% of the steady-state value, set a threshold value of 0.05
.
Visible
— Settling time visibility
"off"
(default) | on/off logical value
Settling time visibility, specified as one of the following logical on/off values:
"on"
,1
, ortrue
— Display the peak response."off"
,0
, orfalse
— Do not display the peak response.
The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
TransientTime
— Transient time
CharacteristicOption
object
Transient time, specified as a CharacteristicOption
object with the following
properties.
Threshold
— Threshold for detecting steady state
0.02
(default) | scalar value between 0 and 1
Threshold for detecting steady state, specified as a scalar value between
0 and 1. For example, to measure when the response remains with 5% of the
steady-state value, set a threshold value of 0.05
.
Visible
— Transient time visibility
"off"
(default) | on/off logical value
Transient time visibility, specified as one of the following logical on/off values:
"on"
,1
, ortrue
— Display the peak response."off"
,0
, orfalse
— Do not display the peak response.
The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
SteadyState
— Steady-state value
CharacteristicOption
object
Steady-state value, specified as a CharacteristicOption
object with the
following property.
Visible
— Steady-state value visibility
"off"
(default) | on/off logical value
Steady-state value visibility, specified as one of the following logical on/off values:
"on"
,1
, ortrue
— Display the peak response."off"
,0
, orfalse
— Do not display the peak response.
The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
ConfidenceRegion
— Confidence region
CharacteristicOption
object
Confidence region for identified models, specified as a
CharacteristicOption
object with the following properties.
Visible
— Confidence region visibility
"off"
(default) | on/off logical value
Confidence region visibility, specified as one of the following logical on/off values:
"on"
,1
, ortrue
— Display the confidence region."off"
,0
, orfalse
— Do not display the confidence region.
The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
NumberOfStandardDeviations
— Number of standard deviations
1
(default) | positive scalar
Number of standard deviations to display for the confidence region, specified as a positive scalar.
Dependencies
ConfidenceRegion
is supported only for identified
models.
TimeUnit
— Time units
"seconds"
| "milliseconds"
| "minutes"
| ...
Time units, specified as one of the following values:
"nanoseconds"
"microseconds"
"milliseconds"
"seconds"
"minutes"
"hours"
"days"
"weeks"
"months"
"years"
Dependencies
By default, the response uses the time units of the plotted linear system. You can override the default units by specifying toolbox preferences. For more information, see Specify Toolbox Preferences for Linear Analysis Plots.
Normalize
— Option to normalize plot
"off"
(default) | on/off logical value
Option to normalize plot, specified as one of the following logical on/off values:
"on"
,1
, ortrue
— Normalize the plot."off"
,0
, orfalse
— Do not normalize the plot.
The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
Visible
— Chart visibility
"on"
(default) | on/off logical value
Chart visibility, specified as one of the following logical on/off values:
"on"
,1
, ortrue
— Display the chart."off"
,0
, orfalse
— Hide the chart without deleting it. You still can access the properties of chart when it is not visible.
The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
.
IOGrouping
— Grouping of inputs and outputs pairs
"none"
(default) | "inputs"
| "outputs"
| "all"
Grouping of inputs and outputs pairs, specified as one of the following:
"none"
— Do not group inputs or outputs."inputs"
— Group only inputs."outputs"
— Group only outputs."all"
— Group all input-output pairs.
InputVisible
— Option to display inputs
on/off logical value | array of on/off logical values
Option to display inputs, specified as one of the following logical on/off values or an array of such values:
"on"
,1
, ortrue
— Display the corresponding input."off"
,0
, orfalse
— Hide the corresponding input.
InputVisible
is an array when the plotted system has multiple inputs. By
default, all inputs are visible in the plot.
The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
or an array of such values.
OutputVisible
— Option to display outputs
on/off logical value | array of on/off logical values
Option to display outputs, specified as one of the following logical on/off values or an array of such values:
"on"
,1
, ortrue
— Display the corresponding output."off"
,0
, orfalse
— Hide the corresponding output.
OutputVisible
is an array when the plotted system has multiple outputs.
By default, all outputs are visible in the plot.
The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState
or an array of such values.
Object Functions
addResponse | Add dynamic system response to existing response plot |
showConfidence | Display confidence regions on response plots for identified models |
Examples
Customize Step Plot
For this example, use the plot handle to change the time units to minutes and turn on the grid.
Generate a random state-space model with 5 states and create the step response plot with chart object sp
.
rng("default")
sys = rss(5);
sp = stepplot(sys);
Change the time units to minutes and turn on the grid. To do so, edit properties of the chart object.
sp.TimeUnit = "minutes"; grid on;
The step plot automatically updates when you modify the chart object.
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"; stepplot(sys,plotoptions);
Depending on your own toolbox preferences, the plot you obtain might look different from this plot. Only the properties that you set explicitly, in this example TimeUnits
and Grid
, override the toolbox preferences.
Display Normalized Response on Step Plot
Generate a step response plot for two dynamic systems.
sys1 = rss(3); sys2 = rss(3); sp = stepplot(sys1,sys2);
Each step response settles at a different steady-state value. Use the plot handle to normalize the plotted response.
sp.Normalize = "on";
Now, the responses settle at the same value expressed in arbitrary units.
Plot Step Responses of Identified Models with Confidence Region
Compare the step response of a parametric identified model to a nonparametric (empirical) model, and view their 3-σ confidence regions. (Identified models require System Identification Toolbox™ software.)
Identify a parametric and a nonparametric model from sample data.
load iddata1 z1 sys1 = ssest(z1,4); sys2 = impulseest(z1);
Plot the step responses of both identified models. Use the plot handle to display the 3-σ confidence regions.
t = -1:0.1:5; sp = stepplot(sys1,'r',sys2,'b',t); showConfidence(sp,3) legend('parametric','nonparametric')
The nonparametric model sys2
shows higher uncertainty.
Customized Step Response Plot at Specified Time
For this example, examine the step response of the following zero-pole-gain model and limit the step plot to tFinal
= 15 s. Use 15-point blue text for the title. This plot should look the same, regardless of the preferences of the MATLAB session in which it is generated.
sys = zpk(-1,[-0.2+3j,-0.2-3j],1)*tf([1 1],[1 0.05]); tFinal = 15;
First, create a default options set using timeoptions
.
plotoptions = timeoptions;
Next change the required properties of the options set plotoptions
.
plotoptions.Title.FontSize = 15; plotoptions.Title.Color = [0 0 1];
Now, create the step response plot using the options set plotoptions
.
h = stepplot(sys,tFinal,plotoptions);
Because plotoptions
begins with a fixed set of options, the plot result is independent of the toolbox preferences of the MATLAB session.
Plot Step Response of Nonlinear Identified Model
Load data for estimating a nonlinear Hammerstein-Wiener model.
load twotankdata z = iddata(y,u,0.2,'Name','Two tank system');
z
is an iddata
object that stores the input-output estimation data.
Estimate a Hammerstein-Wiener Model of order [1 5 3] using the estimation data. Specify the input nonlinearity as piecewise linear and output nonlinearity as one-dimensional polynomial.
sys = nlhw(z,[1 5 3],idPiecewiseLinear,idPolynomial1D);
Create an option set to specify input offset and step amplitude level.
opt = RespConfig(InputOffset=2,Amplitude=0.5);
Plot the step response until 60 seconds using the specified options.
stepplot(sys,60,opt);
Version History
Introduced in R2012aR2024b: Improved customization workflows and integration with MATLAB plotting tools
Starting in R2024b, stepplot
returns a StepPlot
chart
object. Previously, the stepplot
function returned a handle to the
resulting plot.
The new chart object allows you to customize your plot using dot notation.
The new chart object also improves integration with MATLAB plotting tools. For example:
You can now add step plots to tiled chart layouts.
Saving and loading a parent figure now maintains full plot interactivity.
You can add a response your step plot using the new
addResponse
function.
The following functionality changes might require updates to your code.
The
gca
function now returns the chart object rather than an axes within the plot.You can no longer access the graphics objects within a step plot using the
Children
property of its parent figure.
See Also
Topics
- Customize Linear Analysis Plots at Command Line (Control System Toolbox)
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)