Main Content

sdo.getParameterFromModel

Get design variables for optimization

    Description

    example

    DesignVars = sdo.getParameterFromModel(modelname) creates model parameter objects for the parameters in an open Simulink® model. You can tune the parameters to satisfy design requirements or compute parameter estimates using sdo.optimize. All parameters are continuously variable, represented by param.Continuous objects.

    example

    DesignVars = sdo.getParameterFromModel(modelname,continParams) creates continuously tunable parameter objects for a specified subset of model parameters listed in continParams.

    example

    DesignVars = sdo.getParameterFromModel(modelname,continParams,discreteParams) creates discrete-valued tunable parameter objects for the model parameters listed in discreteParams. If you want to specify discrete parameters only, set continParams = []. Use discreteParams = "*" to designate all model parameters (or all parameters not listed in continParams) as discrete. Discrete parameters are represented by param.Discrete parameter objects. Note that to optimize discrete parameters, you must set the optimization method of sdo.optimize to surrogateopt (see sdo.OptimizeOptions).

    Examples

    collapse all

    Load a Simulink model.

    load_system("sldo_model1_stepblk")

    If you do not specify any model parameters, sdo.getParameterFromModel finds all the tunable parameters in the model and treats them as continuous parameters.

    DesignVars = sdo.getParameterFromModel("sldo_model1_stepblk");
    DesignVars
     
    DesignVars(1,1) =
     
           Name: 'Kd'
          Value: 0
        Minimum: -Inf
        Maximum: Inf
           Free: 1
          Scale: 1
           Info: [1x1 struct]
    
     
    DesignVars(2,1) =
     
           Name: 'Ki'
          Value: 0
        Minimum: -Inf
        Maximum: Inf
           Free: 1
          Scale: 1
           Info: [1x1 struct]
    
     
    DesignVars(3,1) =
     
           Name: 'Kp'
          Value: 1
        Minimum: -Inf
        Maximum: Inf
           Free: 1
          Scale: 1
           Info: [1x1 struct]
    
     
    DesignVars(4,1) =
     
           Name: 'w0'
          Value: 0.5000
        Minimum: -Inf
        Maximum: Inf
           Free: 1
          Scale: 0.5000
           Info: [1x1 struct]
    
     
    DesignVars(5,1) =
     
           Name: 'zeta'
          Value: 0.5000
        Minimum: -Inf
        Maximum: Inf
           Free: 1
          Scale: 0.5000
           Info: [1x1 struct]
    
     
    5x1 param.Continuous
     
    

    Thus, for this model, which has tunable parameters Kd, Ki, Kp, w0, and zeta, the output DesignVars is an array of five param.Continuous objects. To prepare the parameters for optimization, you can set the initial value, minimum and maximum values, and free elements of each parameter as needed. For instance, set the minimum value of Kd to 0.001, the maximum value to 100, and the initial value to 1.

    DesignVars(1).Minimum = 1e-3;
    DesginVars(1).Maximum = 100;
    DesignVars(1).Value = 1;

    Instead of designating all tunable model parameters as design variables for optimization, you can specify a subset of variables. Load a Simulink model that has five tunable parameters: Kp, Ki, Kd, w0, and zeta. Configure Kp, Ki, and Kd as continuous design variables.

    mdl = "sldo_model1_stepblk";
    open_system(mdl)
    
    continParams = ["Ki","Kp","Kd"];
    DesignVars = sdo.getParameterFromModel(mdl,continParams)
     
    DesignVars(1,1) =
     
           Name: 'Ki'
          Value: 0
        Minimum: -Inf
        Maximum: Inf
           Free: 1
          Scale: 1
           Info: [1x1 struct]
    
     
    DesignVars(2,1) =
     
           Name: 'Kp'
          Value: 1
        Minimum: -Inf
        Maximum: Inf
           Free: 1
          Scale: 1
           Info: [1x1 struct]
    
     
    DesignVars(3,1) =
     
           Name: 'Kd'
          Value: 0
        Minimum: -Inf
        Maximum: Inf
           Free: 1
          Scale: 1
           Info: [1x1 struct]
    
     
    3x1 param.Continuous
     
    

    DesignVars is a vector of three param.Continuous objects corresponding to Ki, Kp, and Kd in the order you specified them. Suppose that you also want to tune w0 and zeta, but you want to restrict them to a finite, discrete set of values. To do so, specify these parameters as the third input argument to sdo.getParameterFromModel.

    discreteParams = ["w0","zeta"];
    DesignVars = sdo.getParameterFromModel(mdl,continParams,discreteParams);

    Now DesignVars is a vector of length five, containing three param.Continuous objects and two param.Discrete objects. For instance, compare the third entry, Ki, with the fourth entry, corresponding to w0.

    DesignVars(3)
     
    ans =
     
           Name: 'Kd'
          Value: 0
        Minimum: -Inf
        Maximum: Inf
           Free: 1
          Scale: 1
           Info: [1x1 struct]
    
     
    1x1 param.Continuous
     
    
    DesignVars(4)
     
    ans =
     
            Name: 'w0'
           Value: 0.5000
        ValueSet: 0.5000
            Free: 1
            Info: [1x1 struct]
    
     
    1x1 param.Discrete
     
    

    The Value properties of the parameters are initialized to their values in the model. To continue with parameter estimation or response optimization, configure the initial values, the Minimum and Maximum properties of the continuous variables, and the ValueSet properties of the discrete parameters as needed. Note that to optimize discrete parameters, you must set the optimization method of sdo.optimize to surrogateopt. This method requires that all continuous parameters have finite minimum and maximum values.

    If you want to designate all model parameters as discrete-valued, you can use the placeholder "*" as an input to sdo.getParameterFromModel to avoid explicitly listing every model parameter in the discreteParams argument. Similarly, if you specify a subset of model parameters in continParams, you can use "*" to specify the remaining parameters as discrete-valued.

    Load a model and designate all model parameters as discrete-valued. To do so, specify [] to indicate that there are no continuous parameters, and "*" to indicate that all parameters are discrete.

    mdl = "sldo_model1_stepblk";
    load_system(mdl)
     
    DesignVars = sdo.getParameterFromModel(mdl,[],"*");
    size(DesignVars)
    ans = 1×2
    
         5     1
    
    

    DesignVars has five entries, corresponding to the five tunable parameters in the model, Kd, Ki, Kp, zeta, and w0. All parameters are represented by param.Discrete parameter objects. For instance, examine the third parameter.

    DesignVars(2)
     
    ans =
     
            Name: 'Ki'
           Value: 0
        ValueSet: 0
            Free: 1
            Info: [1x1 struct]
    
     
    1x1 param.Discrete
     
    

    Now, suppose that only w0 is continuous-valued, while you want to limit all remaining parameters to discrete values.

    DesignVars = sdo.getParameterFromModel(mdl,"w0","*");

    DesignVars still contains five entries, but this time the first entry is a param.Continuous parameter object.

    DesignVars(1)
     
    ans =
     
           Name: 'w0'
          Value: 0.5000
        Minimum: -Inf
        Maximum: Inf
           Free: 1
          Scale: 0.5000
           Info: [1x1 struct]
    
     
    1x1 param.Continuous
     
    

    The remaining entries are discrete parameters.

    Input Arguments

    collapse all

    Simulink model name, specified as a string scalar or character vector.

    Continuous parameters, specified a string scalar, a string vector, a character vector, a cell array of character vectors, or the empty vector [].

    • To specify a single parameter, you can use a string scalar or a character vector, such as "Vc" or 'Vc'.

    • To specify multiple parameters, you can use a string array or a cell array of character vectors, such as ["m","k","c"] or {'Kp','Ki'}.

    • If you want to specify only discrete parameters, set continParams to the empty vector [], and list the parameters with the discparams argument.

    If a parameter is in a referenced model, the variable name must include the path. For instance, suppose you have model TopLevelModel containing a referenced model Controller and you want to tune parameter Ki.

    • If the parameter Ki is in the referenced model Controller, use continParams = "Controller:Ki".

    • If Ki is a model argument in a referenced model, provide the block path from the top-level model. Thus, if ControlBlock is the name of the block containing Ki in the referenced model Controller, use continParams = "TopLevelModel/ControlBlock:Ki". For an example that uses model arguments in response optimization, see Design Optimization Tuning Parameters in Referenced Models (Code).

    Discrete parameters, specified a string scalar, a string vector, a character vector, or a cell array of character vectors.

    • To specify a single parameter, you can use a string scalar or a character vector, such as "Vc" or 'Vc'.

    • To specify multiple parameters, you can use a string array or a cell array of character vectors, such as ["m","k","c"] or {'Kp','Ki'}.

    • To designate all parameters in the model (or all parameters not explicitly listed in continParams) as discrete, use the placeholder "*" or '*'.

    If a parameter is in a referenced model, the variable name must include the path, as described for the continParams argument.

    Note

    To use discrete parameters for response optimization or parameter estimation, you must use the surrogateopt optimization method, specified with sdo.OptimizeOptions.

    Output Arguments

    collapse all

    Tunable parameters, returned as a param.Continuous object, a param.Discrete object, or an array of such parameter objects.

    • If you do not specify continParams or discreteParams, then sdo.getParameterFromModel treats all tunable parameters in the model as continuous variables, and Designvars is an array of param.Continuous objects corresponding to those parameters.

    • If you specify only continParams, then Designvars is an array of param.Continuous objects corresponding to the parameters listed in continParams, or a single param.Continuousobject if continParams contains only one name.

    • If you set continParams = [] and specify discreteParams, then Designvars is an array of param.Discrete objects corresponding to the parameters listed in discreteParams, or a single param.Discrete object if discreteParams contains only one name.

    • If you specify parameters in both continParams and discreteParams, then DesignVars is whose first Nc elements are param.Continuous objects corresponding to the Nc parameters listed in continParams, and whose remaining Nd elements are param.Discrete objects corresponding to the Nd parameters listed in discreteParams.

    sdo.getParameterFromModel initializes the Value property of each parameter object in Designvars to the current value of the parameter in the model.

    Version History

    Introduced in R2011b

    expand all