sdo.getParameterFromModel
Get design variables for optimization
Syntax
Description
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 DesignVars
= sdo.getParameterFromModel(modelname
)sdo.optimize
. All parameters are continuously
variable, represented by param.Continuous
objects.
creates continuously tunable parameter objects for a specified subset of model parameters
listed in DesignVars
= sdo.getParameterFromModel(modelname
,continParams
)continParams
.
creates discrete-valued tunable parameter objects for the model parameters listed in
DesignVars
= sdo.getParameterFromModel(modelname
,continParams
,discreteParams
)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
Get All Model Parameters as Continuous Design Variables for Optimization
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;
Get Specified Model Parameters as Continuous or Discrete Design Variables
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.
Specify All Parameters as Discrete-Valued
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
modelname
— Simulink model name
string scalar | character vector
Simulink model name, specified as a string scalar or character vector.
continParams
— Continuous parameters
string scalar | string vector | character vector | cell array of character vectors | []
Continuous parameters, specified as 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 a
Simulink.Parameter
object with a one-dimensional or multidimensional value, you can use a string scalar or a character vector, such as"param"
or'param'
.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 thediscparams
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 modelController
, usecontinParams = "Controller:Ki"
.If
Ki
is a model argument in a referenced model, provide the block path from the top-level model. Thus, ifControlBlock
is the name of the block containingKi
in the referenced modelController
, usecontinParams = "TopLevelModel/ControlBlock:Ki"
. For an example that uses model arguments in response optimization, see Design Optimization Tuning Parameters in Referenced Models (Code).
discreteParams
— Discrete parameters
string scalar | string vector | character vector | cell array of character vectors | "*"
| '*'
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 specify a
Simulink.Parameter
object with a one-dimensional or multidimensional value, you can use a string scalar or a character vector, such as"param"
or'param'
.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
DesignVars
— Tunable parameters
param.Continuous
object | param.Discrete
object | vector of param.Continuous
and param.Discrete
objects
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
ordiscreteParams
, thensdo.getParameterFromModel
treats all tunable parameters in the model as continuous variables, andDesignvars
is an array ofparam.Continuous
objects corresponding to those parameters.If you specify only
continParams
, thenDesignvars
is an array ofparam.Continuous
objects corresponding to the parameters listed incontinParams
, or a singleparam.Continuous
object ifcontinParams
contains only one name.If you set
continParams = []
and specifydiscreteParams
, thenDesignvars
is an array ofparam.Discrete
objects corresponding to the parameters listed indiscreteParams
, or a singleparam.Discrete
object ifdiscreteParams
contains only one name.If you specify parameters in both
continParams
anddiscreteParams
, thenDesignVars
is whose firstNc
elements areparam.Continuous
objects corresponding to theNc
parameters listed incontinParams
, and whose remainingNd
elements areparam.Discrete
objects corresponding to theNd
parameters listed indiscreteParams
.
sdo.getParameterFromModel
initializes the
Value
property of each parameter object in
Designvars
to the current value of the parameter in the
model.
Alternatives
Version History
Introduced in R2011bR2022b: Discrete-Valued Variables for Mixed-Integer Optimization
Use the discreteParams
argument in the new syntax
DesignVars =
sdo.getParameterFromModel(modelname,continParams,discreteParams)
to specify
model parameters that are limited to a finite set of discrete values. The function
represents discrete parameters as param.Discrete
objects.
See Also
sdo.optimize
| sdo.setValueInModel
| param.Discrete
| param.Continuous
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)