Main Content


Replace or update control design blocks in generalized model



Mnew = replaceBlock(M,Block1,Value1,...,BlockN,ValueN) replaces the control design blocks Block1,...,BlockN of M with the specified values Value1,...,ValueN. M is a generalized LTI model or a generalized matrix.


Mnew = replaceBlock(M,blockvalues) specifies the block names and replacement values as field names and values of the structure blockvalues.

Mnew = replaceBlock(___,mode) performs block replacement on an array of models M using the substitution mode specified by mode.


collapse all

This example shows how to replace a tunable PID controller (tunablePID) in a Generalized LTI model by a pure gain, a numeric PI controller, or the current value of the tunable controller.

Create Generalized LTI Model

Create a Generalized LTI model of the following system:

where the plant G(s)=(s-1)(s+1)3, and C is a tunable PID controller.

G = zpk(1,[-1,-1,-1],1);
C = tunablePID(C='pid');
Try = feedback(G*C,1)
Generalized continuous-time state-space model with 1 outputs, 1 inputs, 4 states, and the following blocks:
  C: Tunable PID controller, 1 occurrences.

Type "ss(Try)" to see the current value and "Try.Blocks" to interact with the blocks.

Replace PID Controller by Pure Gain Value

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 PID Controller by Numeric PI Controller

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 PID Controller by Current Value

Replace C by its current (nominal) value.

T3 = replaceBlock(Try,C=[]);

T3 is a ss model where C has been replaced by getValue(C).

Consider the second-order filter represented by:


Sample this filter at varying values of the damping constant ζ and the natural frequency ωn. Create a tunable model of the filter by using tunable elements for ζ and ωn.

wn = realp('wn',3);
zeta = realp('zeta',0.8);
F = tf(wn^2,[1 2*zeta*wn wn^2])
Generalized continuous-time state-space 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 and "F.Blocks" to interact with the blocks.

Create a grid of sample values.

wnvals = [3;5];
zetavals = [0.6 0.8 1.0];
[wngrid,zetagrid] = ndgrid(wnvals,zetavals);
Fsample = replaceBlock(F,'wn',wngrid,'zeta',zetagrid);
2x3 array of state-space models.
Each model has 1 outputs, 1 inputs, and 2 states.

The ndgrid command produces a full 2-by-3 grid of parameter combinations. Thus, Fsample is a 2-by-3 array of state-space models. Each entry in the array is a state-space model that represents F evaluated at the corresponding (wn, zeta) pair. For example, Fsample(:,:,2,3) has wn = 5 and zeta = 1.0.

   Pole        Damping       Frequency      Time Constant  
                           (rad/seconds)      (seconds)    
 -5.00e+00     1.00e+00       5.00e+00         2.00e-01    
 -5.00e+00     1.00e+00       5.00e+00         2.00e-01    

Input Arguments

collapse all

Generalized model, specified as a generalized LTI model, a generalized matrix, or an array of such models.

Name of control design block in M, specified as a string or character vector. The replaceBlock function replaces each specified block of M with the corresponding values from Value1,...,ValueN.

If a specified Block is not a block of M, replaceBlock ignores that block and the corresponding value.

Replacement block value for the corresponding block from Block1,...,BlockN, specified as a control design block, numeric matrix, or LTI model that is compatible with the size of the block.

If a value is [], the corresponding block is replaced by its nominal (current) value.

Block replacements, specified as a structure.

The field names of blockvalues match names of control design blocks of M. Use the field values to specify the replacement values for the corresponding blocks of M. The replacement values may be control design blocks, LTI models, or numeric matrices.

For example, synchronize the values of block M with the values in block M0.

M = replaceBlock(M,M0.Blocks);

Block replacement mode when M is a model array, specified as one of the following values.

  • '-once' (default) — Vectorized block replacement across the model array M. Each block is replaced by a single value, but the value may change from model to model across the array.

    For vectorized block replacement, use a structure array for the input blockvalues, or cell arrays for the Value1,...,ValueN inputs. For example, if M is a 2-by-3 array of models:

    • Mnew = replaceBlock(M,blockvalues,'-once'), where blockvalues is a 2-by-3 structure array, specifies one set of block values blockvalues(k) for each model M(:,:,k) in the array.

    • Mnew = replaceBlock(M,Block,Value,'-once'), where Value is a 2-by-3 cell array, replaces Block by Value{k} in the model M(:,:,k) in the array.

  • '-batch' — Batch block replacement. Each block is replaced by an array of values, and the same array of values is used for each model in M. The resulting array of model Mnew is of size [size(M) Asize], where Asize is the size of the replacement value.

When M is a single model, '-once' and '-batch' return identical results.

Output Arguments

collapse all

Updated model returned as a generalized LTI model, generalized matrix or an array of such models.

When all the specified replacement values are numeric values or numeric LTI models, Mnew is a numeric array or numeric LTI model.


  • Use replaceBlock to perform parameter studies by sampling generalized LTI models across a grid of parameters, or to evaluate tunable models for specific values of the tunable blocks.

  • For additional options for sampling control design blocks, including concurrent sampling, use sampleBlock.

  • To take random samples of control design blocks, see rsampleBlock.

Version History

Introduced in R2011a