Replace or update Control Design Blocks in Generalized LTI model
Mnew = replaceBlock(M,Block1,Value1,...,BlockN,ValueN)
Mnew = replaceBlock(M,blockvalues)
Mnew = replaceBlock(...,mode)
replaces
the Control
Design Blocks Mnew
= replaceBlock(M
,Block1,Value1,...,BlockN,ValueN)Block1,...,BlockN
of M
with
the specified values Value1,...,ValueN
. M
is
a Generalized
LTI model or a Generalized matrix.
specifies
the block names and replacement values as field names and values of
the structure Mnew
= replaceBlock(M
,blockvalues
)blockvalues
.
performs
block replacement on an array of models Mnew
= replaceBlock(...,mode
)M
using
the substitution mode specified by the string mode
.

Generalized LTI model, Generalized matrix, or array of such models. 

Names of Control Design Blocks in If a specified 

Replacement values for the corresponding blocks The replacement value for a block can be any value compatible
with the size of the block, including a different Control Design Block,
a numeric matrix, or an LTI model. If any value is 

Structure specifying blocks of The field names of 

String specifying the block replacement mode for an input array
When the input Default: 

Matrix or linear model or matrix where the specified blocks are replaced by the specified replacement values.

This example shows how to replace a tunable PID controller (ltiblock.pid
) in a Generalized LTI model
by a pure gain, a numeric PI controller, or the current value of the
tunable controller.
Create a Generalized LTI model of the following system:
where the plant $$G\left(s\right)=\frac{\left(s1\right)}{{\left(s+1\right)}^{3}}$$, and C is a tunable PID controller.
G = zpk(1,[1,1,1],1); C = ltiblock.pid('C','pid'); Try = feedback(G*C,1)
Replace C
by a pure gain of 5.
T1 = replaceBlock(Try,'C',5);
T1
is a ss
model
that equals feedback(G*5,1)
.
Replace C
by a PI controller with
proportional gain of 5 and integral gain of 0.1.
C2 = pid(5,0.1); T2 = replaceBlock(Try,'C',C2);
T2
is a ss
model that
equals feedback(G*C2,1)
.
Replace C
by its current (nominal)
value.
T3 = replaceBlock(Try,'C',[]);
T3
is a ss
model where C
has
been replaced by getValue(C)
.
This example shows how to sample a parametric model of a secondorder filter across a grid of parameter values using replaceBlock
.
Consider the secondorder filter represented by:
Sample this filter at varying values of the damping constant and the natural frequency . Create a parametric model of the filter by using tunable elements for and .
wn = realp('wn',3); zeta = realp('zeta',0.8); F = tf(wn^2,[1 2*zeta*wn wn^2])
F = Generalized continuoustime statespace model with 1 outputs, 1 inputs, 2 states, and the following blocks: wn: Scalar parameter, 5 occurrences. zeta: Scalar parameter, 1 occurrences. Type "ss(F)" to see the current value, "get(F)" to see all properties, and "F.Blocks" to interact with the blocks.
F
is a genss
model with two tunable Control Design Blocks, the realp
blocks wn
and zeta
. The blocks wn
and zeta
have initial values of 3 and 0.8, respectively.
Sample F
over a 2by3 grid of (wn
, zeta
) values.
wnvals = [3;5]; zetavals = [0.6 0.8 1.0]; [wngrid,zetagrid] = ndgrid(wnvals,zetavals); Fsample = replaceBlock(F,'wn',wngrid,'zeta',zetagrid);
The ndgrid
command produces a full 2by3 grid of parameter combinations. Fsample
is a 2by3 array of statespace models. Each entry in the array is a statespace model that represents F
evaluated at the corresponding (wn
, zeta
) pair. For example, Fsample(:,:,2,3)
has wn
= 5 and zeta
= 1.0.
Set the SamplingGrid
property of the model array to help keep track of which set of parameter values corresponds to which entry in the array. To do so, create a grid of parameter values that matches the dimensions of the array. Then, assign these values to Fsample.SamplingGrid
in a structure with the parameter names.
Fsample.SamplingGrid = struct('wn',wngrid,'zeta',zetagrid);
When you display Fsample
, the parameter values in Fsample.SamplingGrid
are displayed along with the each transfer function in the array. The parameter information is also available in response plots. For instance, examine the step response of Fsample
.
stepplot(Fsample)
The step response plots show the variation in the natural frequency and damping constant across the six models in the array. When you click on one of the responses in the plot, the datatip includes the wn
and zeta
values as specified in Fsample.SamplingGrid
.