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 signals
field,
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 time
field,
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, in1,
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.
Each signals
substructure must contain two
fields: values
and dimensions
.
The 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 time
field.
If the inputs for a port are scalar or vector values, the values
field
must be an M-by-N
array. If you specify a time
vector, M
must be the number of time points specified
by the time
field and N
is the
length of each vector value.
If the inputs for a port are matrices (2-D arrays), the values
field
must be an M-by-N-by-T
array. M
and N
are
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 dimensions
field
of the workspace structure must equal [4 5]
and
the values
array must have the dimensions 4-by-5-by-51
.
The dimensions
field specifies the dimensions
of the input. If each input is a scalar or vector (1-D array) value,
the 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
vector whose:
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 int8
into
the model:
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 a
.
In the Inport block dialog box, in the Signal
Attributes tab, set Port dimensions to 2
and Data
type to int8
.
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, a
,
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.
Note:
In this model you do not need to specify the dimension and data
type, because the default values are |