setVariable
Set variable values for simulation using
SimulationInput or Simulation
object
Description
sets the value of the variable s = setVariable(s,varname,varvalue)varname to the value
varvalue for the simulation configured using the
Simulink.SimulationInput or Simulation object
s. Use this syntax to specify values for variables in the
base workspace or data dictionaries. The variable values you specify override the
variable values saved in the base workspace or data dictionary during simulation and
are reverted when the simulation completes.
When
sis aSimulationInputobject, you can specify only a single value for each variable to use for the entire simulation.When
sis aSimulationobject, you can specify a single value for each variable to use at the start of the simulation and specify new values during simulation for variables that define tunable values.
You can specify values for multiple variables on a
SimulationInput or Simulation object. Specify
the value for each variable one at a time.
sets the value of the variable s = setVariable(s,varname,varvalue,Workspace=mdl)varname in the model workspace
of the model mdl.
By default, when you do not specify the Workspace argument,
variables on a SimulationInput or Simulation
object are scoped to a global workspace specific to each object. Variables in the
global workspace of a SimulationInput or
Simulation object override variables with the same name in the
base workspace and in data dictionaries but not in the model workspace.
Use this syntax to specify the value of a variable in a model workspace for a
simulation configured using a SimulationInput or
Simulation object.
Examples
Input Arguments
Output Arguments
Tips
To remove a variable from a
SimulationInputorSimulationobject, use theremoveVariablefunction.To get the value set on a
SimulationInputorSimulationobject for a specific variable, use thegetVariablefunction. For example, this command gets the value of the variable namedMyVariable.varvalue = getVariable(s,"MyVariable");
To run multiple simulations with large number of variables (for example, over a hundred variables), use the
loadVariablesFromMATFilefunction to load variables into theSimulink.SimulationInputobject. UsingloadVariablesFromMATFilefor large number of variables is faster than usingsetVariable.