Option set for
Create Default Option Set for Model Simulation
opt = simOptions;
Specify Options for Model Simulation
Create an option set for
sim specifying the following options.
Zero initial conditions
Input offset of 5 for the second input of a two-input model
opt = simOptions('InitialCondition','z','InputOffset',[0; 5]);
Add Noise to Simulation Output
Create noise data for a simulation with
500 input data samples and two outputs.
noiseData = randn(500,2);
Create a default option set.
opt = simOptions;
Modify the option set to add the noise data.
opt.AddNoise = true; opt.NoiseData = noiseData;
Use Historical Data to Specify Initial Conditions for Model Simulation
Use historical input-output data as a proxy for initial conditions when simulating your model.
Load a two-input, one-output data set.
load iddata7 z7
Identify a fifth-order state-space model using the data.
sys = n4sid(z7, 5);
Split the data set into two parts.
zA = z7(1:15); zB = z7(16:end);
Simulate the model using the input signal in
uSim = zB;
Simulation requires initial conditions. The signal values in
zA are the historical data, that is, they are the input and output values for the time immediately preceding data in
zA as a proxy for the required initial conditions.
IO = struct('Input',zA.InputData,'Output',zA.OutputData); opt = simOptions('InitialCondition',IO);
Simulate the model.
ysim = sim(sys,uSim,opt);
To understand how the past data is mapped to the initial states of the model, see Understand Use of Historical Data for Model Simulation.
Obtain and Apply Estimated Initial Conditions
Load and plot the data.
load iddata1ic z1i plot(z1i)
Examine the initial value of the output data
ystart = z1i.y(1)
ystart = -3.0491
The measured output does not start at 0.
Estimate a second-order transfer function
sys and return the estimated initial condition
[sys,ic] = tfest(z1i,2,1); ic
ic = initialCondition with properties: A: [2x2 double] X0: [2x1 double] C: [0.2957 5.2441] Ts: 0
ic is an
initialCondition object that encapsulates the free response of
sys, in state-space form, to the initial state vector in
sys using the estimation data but without incorporating the initial conditions. Plot the simulated output with the measured output.
y_no_ic = sim(sys,z1i); plot(y_no_ic,z1i) legend('Model Response','Output Data')
The measured and simulated outputs do not agree at the beginning of the simulation.
Incorporate the initial condition into the
simOptions option set.
opt = simOptions('InitialCondition',ic); y_ic = sim(sys,z1i,opt); plot(y_ic,z1i) legend('Model Response','Output Data')
The simulation combines the model response to the input signal with the free response to the initial condition. The measured and simulated outputs now have better agreement at the beginning of the simulation. This initial condition is valid only for the estimation data
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name in quotes.
default Gaussian white noise to the response model and specifies an
input offset of
5 for the first of two model inputs.
InitialCondition — Simulation initial conditions
 (default) | column vector | matrix |
initialCondition object | object array | structure | structure array |
Simulation initial conditions, specified as one of the following:
'z'— Zero initial conditions.
Numerical column vector of initial states with length equal to the model order.
For multiexperiment data, specify a matrix with Ne columns, where Ne is the number of experiments, to configure the initial conditions separately for each experiment. Otherwise, use a column vector to specify the same initial conditions for all experiments.
initialConditionobject that represents a model of the free response of the system to initial conditions. For multiexperiment data, specify a 1-by-Ne array of objects, where Ne is the number of experiments.
Use this option for linear models only. For an example, see Obtain and Apply Estimated Initial Conditions.
Structure with the following fields, which contain the historical input and output values for a time interval immediately before the start time of the data used in the simulation:
Input history, specified as a matrix with Nu columns, where Nu is the number of input channels. For time-series models, use
. The number of rows must be greater than or equal to the model order.
Output history, specified as a matrix with Ny columns, where Ny is the number of output channels. The number of rows must be greater than or equal to the model order.
For an example, see Use Historical Data to Specify Initial Conditions for Model Simulation.
For multiexperiment data, configure the initial conditions separately for each experiment by specifying
InitialConditionas a structure array with Ne elements. To specify the same initial conditions for all experiments, use a single structure.
The software uses
data2stateto map the historical data to states. If your model is not
idnlarx, the software first converts the model to its state-space representation and then maps the data to states. If conversion of your model to
idssis not possible, the estimated states are returned empty.
'model'— Use this option for
idnlgreymodels only. The software sets the initial states to the values specified in the
sys.InitialStatesproperty of the model
— Corresponds to zero initial conditions for all models except
idnlgreymodels, the software treats
'model'and specifies the initial states as
X0Covariance — Covariance of initial states vector
 (default) | matrix
Covariance of initial states vector, specified as one of the following:
Positive definite matrix of size Nx-by-Nx, where Nx is the model order.
For multiexperiment data, specify as an Nx-by-Nx-by-Ne matrix, where Ne is the number of experiments.
— No uncertainty in the initial states.
Use this option only for state-space models (
'InitialCondition' is specified as a column
vector. Use this option to account for initial condition uncertainty
when computing the standard deviation of the simulated response of
InputInterSample — Input-channel intersample behavior
Input-channel intersample behavior for transformations between discrete time and continuous time, specified as
The definitions of the three behavior values are as follows:
'zoh'— Zero-order hold maintains a piecewise-constant input signal between samples.
'foh'— First-order hold maintains a piecewise-linear input signal between samples.
'bl'— Band-limited behavior specifies that the continuous-time input signal has zero power above the Nyquist frequency.
iddata objects have a similar property,
data.InterSample, that contains the same behavior value options.
InputInterSample value is
the estimation data is in an
software uses the
data.InterSample value. When the estimation data
is instead contained in a timetable or a matrix pair, with the
option, the software uses
The software applies the same option value to all channels and all experiments.
OutputTimes — Times at which the output is calculated
 (default) | vector | cell array
Times at which the output is calculated, specified as one of the following:
. This is the default option, in which output times are not specified. For systems with inputs, the output sample times are chosen to be the same as those of the input signals. For autonomous systems (that is, systems with no inputs) a non-empty value for
OutputTimesmust be specified, otherwise, an error is generated during simulation.
Time span [tMin, tMax], where tMin and tMax are expressed in the time units of the model.
Time vector. A column vector of doubles. For models with inputs, the time vector must be contained within the time span of the simulation inputs (that is entries cannot be outside the time range of the input signals). For discrete-time models, the time interval must match the model sample time.
Cell array. This option is used for multi-experiment simulations. Each element of the cell contains an array of time spans or time vectors, one array for each data experiment.
opt — Option set for
simOptions option set
Option set for
sim command, returned as
simOptions option set.
Version HistoryIntroduced in R2012a
InputInterSample option allows intersample behavior specification for continuous models estimated from timetables or matrices.
iddata objects contain an
InterSample property that
describes the behavior of the signal between sample points. The
InputInterSample option implements a version of that property in
simOptions so that intersample behavior can be specified also when
estimation data is stored in timetables or matrices.