Customize Linear Analysis Plots at Command Line
After you create a linear analysis response plot, you can programmatically edit the plot properties using a chart object. Programmatically editing response plot properties allows you to:
Efficiently customize a large number of plots in a batch analysis process.
Add response plots to a UI and update plot appearance based on user input.
You can also interactively modify individual response plot properties using the:
Property Editor — For more information, see Customize Linear Analysis Plots Using Property Editor.
Chart Objects
To programmatically customize response plots, you must create the plot using one of the plotting functions in the following table. Each function returns a chart object whose properties you can modify using dot notation.
Plot Type | Plot Function | Chart Object Properties |
---|---|---|
Bode magnitude and phase | bodeplot | BodePlot Properties |
Hankel singular values | hsvplot | HSVPlot Properties |
Impulse response | impulseplot | ImpulsePlot Properties |
Initial condition | initialplot | InitialPlot Properties |
Pole/zero maps for input/output pairs | iopzplot | IOPZPlot Properties |
Time response to arbitrary inputs | lsimplot | LSimPlot Properties |
Nichols chart | nicholsplot | NicholsPlot Properties |
Nyquist | nyquistplot | NyquistPlot Properties |
Pole/zero | pzplot | PZPlot Properties |
Root locus | rlocusplot | RLocusPlot Properties |
Singular values of the frequency response | sigmaplot | SigmaPlot Properties |
Step response | stepplot | StepPlot Properties |
For more information on specifying properties for a response plot, see the corresponding chart object properties. By modifying the chart object properties, you can customize plot features such as:
Titles and axis label text and font appearance
Axis limits and units
Response appearance, such as line color, style, and weight
Time or frequency vectors
Grid visibility and color
Input and output visibility for MIMO plots
Response characteristics to display, such as rise time or stability margins
You can also add responses to an existing plot using addResponse
or
modify the model associated with a response using dot notation.
Customize Linear Analysis Plot Appearance
Once you plot the response for a linear system, you can modify the plot appearance using dot notation. As an example, create a step plot for a transfer function model.
sys = tf(4,[1 0.5 4]); sp = stepplot(sys);
To customize the plot appearance, modify the properties of chart object sp
using dot notation. For example, change the line color and width for the response.
sp.Responses.Color = "black";
sp.Responses.LineWidth = 2;
You can also modify the units for a plot. By default, the step response uses the time units of the plotted linear system. For sys
, the time unit is seconds. Change the units of the plot to minutes.
sp.TimeUnit = "minutes";
The x-axis label updates to reflect the change of unit. Changing the plot units does not change the time units of the underlying model. To change the model time units, do so before plotting the response.
You can also modify the plot title and axis labels for the plot. For example, change the title text, increase the size of the title font, and make the axes labels to bold.
sp.Title.String = "Step Plot"; sp.Title.FontSize = 16; sp.XLabel.FontWeight = "bold"; sp.YLabel.FontWeight = "bold";
Depending on the plot type, you can configure and display response characteristics in the plot. For example, display the settling time on the step plot.
sp.Characteristics.SettlingTime.Visible = "on";
Modify or Add Linear Model Response
Once you create a response plot, you can modify the properties of the linear system and update the plot. Doing so helpful for examining the impact of varying model parameters or for updating response plots in a UI based on user input.
As an example, consider the Bode response for a state-space model.
sys = ss([-4.5 -6;0.6 0.7],[0;-1.5],[-1.1 0],-0.5); bp = bodeplot(sys);
You can modify the linear system for the plot by changing the source data for the response. For example, remove the feedthrough component of the plotted state-space model by setting the D matrix to zero.
bp.Responses.SourceData.Model.D = 0;
You can also replace the model in a response plot with a new model object. For example, consider a second-order dynamic system with damping ratio zeta
.
zeta = 0.5; wn = 2; sys2 = tf(wn^2,[1 2*zeta*wn wn^2]);
Plot the step response for this system.
sp = stepplot(sys2);
You can update the damping ratio of the model by creating a new transfer function model and replacing the model source data.
newZeta = 0.75; sys3 = tf(wn^2,[1 2*newZeta*wn wn^2]); sp.Responses.SourceData.Model = sys3;
You can also add a response to an existing plot using the addResponse
function. For example, create a step response for sys2
and subsequently add the response for sys3
.
sp2 = stepplot(sys2);
addResponse(sp2,sys3);
sp2.LegendVisible = "on";
If you have a plot with multiple responses, you can suppress the display of one or more plots without removing the corresponding response from the chart object. For example, hide the second response in the plot.
sp2.Responses(2).Visible = "off";