The Simulink® software can load data from the workspace in the form of a structure, whose name you specify in the Configuration Parameters > Data Import/Export > Input parameter.
For information about defining MATLAB® structures, see Create a Structure Array in the MATLAB documentation.
The structure always includes a signals substructure, which contains a values field and a dimensions field. For details about the signal data, see Specify Signal Data. Depending on the modeling task that you want to perform, the structure can also include a time field.
You can specify structures for the model as a whole or on a per-port basis. For information about specifying per-port structures for the Input parameter, see Structures for All Ports or for Each Port.
The form of a structure that you use depends on whether you are importing data for:
Discrete signals (the signal is defined at evenly spaced values of time) — Use a structure that has an empty time vector.
Continuous signals (the signal is defined for all values of time) — The approach that you use depends on whether the data represents a smooth curve or a curve that has discontinuities (jumps) over its range.
For details, see:
For both discrete and continuous signals, specify a
which contains an array of substructures, each of which corresponds
to a model input port. For details, see Specify Signal Data.
For continuous signals, you can specify a
which contains a time vector. See Specify Time Data.
You can specify one structure to provide input to all root-level input ports in a model, or you can specify a separate structure for each port.
The per-port structure format consists of a separate structure-with-time
or structure-without-time for each port. The input data structure
for each has only one
signals field. To specify
this option, enter the names of the structures in the Input text field as a comma-separated list,
in2,..., inN. The value
in1 is the data
for first input port in the model,
in2 for the
second input port, and so on.
The rest of the section about importing structure data focuses on specifying one structure for all ports.
signals substructure must contain two
values field must contain an array of
inputs for the corresponding input port. If you specify a time vector,
each input must correspond to a time value specified in the
If the inputs for a port are scalar or vector values, the
must be an
M-by-N array. If you specify a time
M must be the number of time points specified
time field and
N is the
length of each vector value.
If the inputs for a port are matrices (2-D arrays), the
must be an
the dimensions of each matrix input and
T is the
number of time points. For example, suppose that you want to input
51 time samples of a 4-by-5 matrix signal into one of the input ports
in your model. Then, the corresponding
of the workspace structure must equal
[4 5] and
values array must have the dimensions
dimensions field specifies the dimensions
of the input. If each input is a scalar or vector (1-D array) value,
dimensions field must be a scalar value specifying
the length of the vector (1 for a scalar). If each input is a matrix
(2-D array), the
dimensions field must be a two-element
First element specifies the number of rows in the matrix
Second element specifies the number of columns
You can specify a time vector of doubles as part of the data structure to import. For example, specify a time vector when importing signal data to represent a continuous plant or to create a test case. To test a discrete algorithm, use a structure with an empty time vector. This table provides additional recommendations for specifying time values, based on the kind of signal data you want to load.
|Signal Data||Time Data Recommendation|
Inport or Trigger block with a discrete sample time
Do not specify a time vector. Simulink loads one signal value at each time step.
Evenly spaced discrete signals
Use an expression in this form:
timeVector = timeStep * [startTime:numSteps-1]'
The vector is transposed. Also, because the start time is a time step, you need specify the number of steps you want minus 1. For example, to specify 50 time values at 0.2 time steps:
T1 = 0.2 * [0:49]'
Unevenly spaced values
Use any valid MATLAB array expression; for example,
The From Workspace, From File, and Signal Builder blocks support zero-crossing detection. If the root-level input port is connected to one of those blocks, you can specify a zero-crossing time by using a duplicate time entry.
In the first example, consider the following model that has a single input port:
Create an input structure for loading 11 time samples
of a two-element signal vector of type
N = 10 Ts = 0.1 a.time = Ts*[0:N]'; c1 = int8([0:1:10]'); c2 = int8([0:10:100]'); a.signals(1).values = [c1 c2]; a.signals(1).dimensions = 2;
In the Configuration Parameters > Data Import/Export > Input parameter edit box, specify the variable
In the Inport block dialog box, in the Signal
Attributes tab, set Port dimensions to
2 and Data
As another example, consider a model that has two inputs:
Suppose that you want to input a sine wave into the first port
and a cosine wave into the second port. Define a structure,
as follows, in the MATLAB workspace:
a.time = 0.1*[0:1]'; a.signals(1).values = sin(a.time); a.signals(1).dimensions = 1; a.signals(2).values = cos(a.time); a.signals(2).dimensions = 1;
Enter the structure name (
a) in the Configuration Parameters > Data
Import/Export > Input parameter edit box.
In this model you do not need to specify the dimension and data
type, because the default values are