To load signal data with a From Workspace block:
Create a workspace variable with the signal data that you want to load.
Add a From Workspace block to a model. Connect the From Workspace block to the block that the From Workspace block provides input to.
Double-click the From Workspace block and configure:
The workspace data to load
The data format for the From Workspace block output
How the data is loaded, including sample time, how data for missing data points are handled, and whether to use zero-crossing detection
Suppose that the workspace contains a column vector of times named
T and a column vector of corresponding signal values named
U. Entering the expression
[T U] for
Data parameter yields the required input array. If the required
array or structure exists in the workspace, enter the name of the structure or matrix in
the Data parameter.
An alternative to using a From Workspace block for loading workspace data is to load data to a root-level input port. For more information, see Root-Level Input Ports.
Double-click the From Workspace block, and in the Data parameter, specify the workspace data to load. Specify a MATLAB® expression (for example, the name of a variable in the MATLAB workspace) that evaluates to one of the following:
Real signals of type
double can be in any format that the From
Workspace block supports. For complex signals and real signals of a data type other than
double, use any format except
A structure of
For bus data, use a structure of
timetable objects. Match the bus hierarchy and specify a
timetable object for each leaf signal in the bus. Set up the data the same
way as you do for loading bus signals to a root-level Inport block. For
details, see Load Bus Data to Root-Level Input Ports.
A structure, with or without time
For details, see Specify Structure Data for the From Workspace Block.
A two-dimensional matrix
You can use a matrix to specify only one-dimensional signals. The first element of each matrix row is a timestamp. The rest of each row is a scalar or vector of signal values.
When you specify
timetable data to load, each
timetable object can contain data for only one signal.
You can use a structure for one-dimensional or multidimensional signals, with or without time values. For the structure, use this format:
signals.values field, which contains a column vector of
signals.dimensions array, which contains the
dimensions of the signal.
time vector of doubles, which is a column vector of
time element is the timestamp of the
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 examples, see:
For both discrete and continuous signals, specify a
which contains an array of substructures, each of which corresponds to a model input
signals substructure must contain two fields:
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
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
field must be an
N are the dimensions of each matrix input and
T is the number of time points. Suppose that you want to input 51
time samples of a 4-by-5 matrix signal into one of your model input ports. Then, the
dimensions field of the workspace structure must
[4 5] and the
values array must have the
dimensions field specifies the dimensions of the input. If
each input is a scalar or vector (1-D array) value, the
field must be a scalar value that specifies 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
and whose second element specifies the number of columns.
For continuous signals, you can specify a
time field, which
contains a time vector. How you specify the time values depends on the kind of signal data
that you want.
For information about defining MATLAB structures, see Create Structure Array (MATLAB).
|Signal Data||Time Data Recommendation|
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]'
Do not use an expression in this form:
timeVector = [startTime:timeStep:endTime]'
For example, do not use:
T2 = [0:0.2:10]'
This time vector form is not equivalent to the form that multiplies by
time steps (
Unevenly spaced values
Use any valid MATLAB array expression; for example,
The From Workspace, From File, and Signal Editor 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.
If you load a structure that does not specify a time vector:
Set Sample time (-1 for inherited) to a value other than
Clear Interpolate data.
Set Form output after final data value by to a value other
You can use the From Workspace block to load data exported by a To
Workspace block in a previous simulation for use in a later simulation. Save the
To Workspace block data in either
Structure with Time format. Loading data that was exported to a
file by a To File block using MATLAB
timeseries does not require that you change the data.
If you set the To File block Save format parameter
Array, transpose the exported array data. The data saved by
the To File block contains columns with consecutive timestamps, followed by
the corresponding data. The transposed data contains rows with consecutive timestamps,
followed by the corresponding data. To provide the required format, use MATLAB
commands with the MAT-file. To avoid transposing the
data again, resave the transposed data.
To use workspace data that is in the
format, extract a
Dataset object. For example, if you use signal logging with the
Dataset format and use the default output variable
logsout, for a single logged signal enter:
You can use a To Workspace block (with the
Structure With Time
format) or a root Outport block to log variable-size signals. Then use the
To Workspace variable with the From Workspace block.
Alternatively, create a MATLAB structure that contains variable-size signal data. For each
values field in the structure, include a
valueDimensions field that specifies the run-time dimensions for the
signal. For details, see Simulink Models Using Variable-Size Signals.
When you use a From Workspace block in a model that is linked to a data dictionary, you must choose the location to store the data that the block refers to. Set the value of the Data parameter based on the workspace or dictionary that contains the target data to load. For more information, see Load Data Using the From Workspace Block.
The From Workspace block Sample time parameter specifies the sample time to load data from a workspace. The timestamps in the workspace data must be monotonically nondecreasing. For details, see Specify Sample Time.
To use linear Lagrangian interpolation to compute data values for time hits that occur between the time hits for which the workspace supplies the data, select Interpolate data.
For variable-size signals, clear Interpolate data.
To determine the block output after the last time hit for which workspace data is available, combine the settings of these parameters:
Form output after final data value by
In the From Workspace block documentation, see the Form output after final data value by parameter.
By default, the From Workspace block does not enable zero-crossing detection. Zero-crossing detection locates discontinuities, without resorting to excessively small time steps.
The Enable zero-crossing detection parameter applies only if the
sample time is continuous (
If you select the Enable zero-crossing detection parameter, and if an input array contains multiple entries for the same time hit, Simulink detects a zero crossing at that time hit.
For bus signals, Simulink detects zero crossings across all leaf bus elements.