Documentation Center

  • Trial Software
  • Product Updates

replaceBlock

Replace or update Control Design Blocks in Generalized LTI model

Syntax

Mnew = replaceBlock(M,Block1,Value1,...,BlockN,ValueN)
Mnew = replaceBlock(M,blockvalues)
Mnew = replaceBlock(...,mode)

Description

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 the string mode.

Input Arguments

M

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

Block1,...,BlockN

Names of Control Design Blocks in M. The replaceBlock command replaces each listed block of M with the corresponding values Value1,...,ValueN that you supply.

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

Value1,...,ValueN

Replacement values for the corresponding blocks Block1,...,BlockN.

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 [], the corresponding block is replaced by its nominal (current) value.

blockvalues

Structure specifying blocks of M to replace and the values with which to replace those blocks.

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 numeric values, Numeric LTI models, Control Design Blocks, or Generalized LTI models.

mode

String specifying the block replacement mode for an input array M of Generalized matrices or LTI models.

mode can take 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 the input M is a single model, '-once' and '-batch' return identical results.

Default: '-once'

Output Arguments

Mnew

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

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

Examples

Replace Control Design Block with Numeric 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.

  1. Create a Generalized LTI model of the following system:

    where the plant , and C is a tunable PID controller.

    G = zpk(1,[-1,-1,-1],1);
    C = ltiblock.pid('C','pid');
    Try = feedback(G*C,1)
  2. Replace C by a pure gain of 5.

    T1 = replaceBlock(Try,'C',5);

    T1 is a ss model that equals feedback(G*5,1).

  3. 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).

  4. Replace C by its current (nominal) value.

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

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

Sample a Parametric Model over a Matrix of Parameter Values.

This example shows how to sample a parametric model of a second-order filter across a grid of parameter values using replaceBlock.

  1. Create a tunable (parametric) model of the second-order filter:

    where the damping ζ and the natural frequency ωn are the parameters.

    wn = realp('wn',3);
    zeta = realp('zeta',0.8);
    F = tf(wn^2,[1 2*zeta*wn wn^2])
    F =
    
      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, "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.

  2. Sample F over a 2-by-3 grid of (wn,zeta) values.

    wnvals = [3;5];
    zetavals = [0.6 0.8 1.0];
    Fsample = replaceBlock(F,'wn',wnvals,'zeta',zetavals);

    Fsample is 2-by-3 array of state-space models. Each entry in the array is the transfer function for the corresponding (wn,zeta) pair.

  3. Plot the step response of Fsample.

    step(Fsample)

    The step response plots show the variation in the natural frequency and damping constant across the six models in the array Fsample.

  4. You can 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 with the parameter names.

    [wngrid,zetagrid] = ndgrid(wnvals,zetavals);
    Fsample.SamplingGrid = struct('wn',wngrid,'zeta',zetagrid);

    When you display H, the parameter values in Fsample.SamplingGrid are displayed along with the each transfer function in the array.

More About

expand all

Tips

  • 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. See Examples.

See Also

| | |

Was this topic helpful?