| Simulink® | ![]() |
Sources
The From Workspace block reads data from a workspace and outputs the data as a signal. The block's Data parameter specifies the workspace data using a MATLAB expression that evaluates to a matrix (2-D array), a structure containing an array of signal values and time steps, or a time series object (see Simulink.Timeseries). The From Workspace icon displays the expression specified in the Data parameter. The Simulink software evaluates this expression as described in Resolving Symbols.
The format of the matrix or structure is the same as that used to load root-level input port data from the workspace. See Importing Data from a Workspace for more information. See the documentation of the sim command for some data import capabilities that are available only for programmatic simulation.
Note You must use the structure-with-time format or a time series object to load matrix (2-D) data from the workspace. |
The From Workspace block's Interpolate data parameter determines the block's output in the time interval for which workspace data is supplied. If you select the Interpolate data option, the block uses linear Lagrangian interpolation to compute data values for time steps that occur between time steps for which the workspace supplies data. In particular, the block linearly interpolates a missing data point from the two known data points between which it falls. For example, suppose the block reads the following time series from the workspace.
time: 1 2 3 4 signal: 253 254 ? 256
In this case, the block would output:
time: 1 2 3 4 signal: 253 254 255 256
If you do not select the Interpolate data option, the block uses the most recent data value supplied from the workspace.
Note The data type of the workspace data can affect interpolated values. See How Data Types Affect Interpolation for more information. |
The block's Form output after final data value by parameter determines the block's output after the last time step for which data is available from the workspace. The following table summarizes the output block based on the options that the parameter provides.
| Form Output Option | Interpolate Option | Block Output After Final Data |
|---|---|---|
Extrapolate | On | Extrapolated from final data value |
Extrapolate | Off | Error |
SettingToZero | On | Zero |
SettingToZero | Off | Zero |
HoldingFinalValue | On | Final value from workspace |
HoldingFinalValue | Off | Final value from workspace |
CyclicRepetition | On | Error |
CyclicRepetition | Off | Repeated from workspace. This option is valid only for workspace data in structure-without-time format. |
If the input array contains more than one entry for the same time step, Simulink software detects a zero crossing at this time step. For example, suppose the input array has this data:
time: 0 1 2 2 3 signal: 2 3 4 5 6
At time 2, there is a zero crossing from input signal discontinuity.
If the interpolation option is on, the block uses the last two known data points to extrapolates data points that occur after the last known point. Consider the following example.

In this example, the From Workspace block reads data from the workspace consisting of the output of the Simulink Sine block sampled at one-second intervals. The workspace contains the first 16 samples of the output. The top and bottom X-Y plots display the output of the Sine Wave and From Workspace blocks, respectively, from 0 to 20 seconds. The straight line in the output of the From Workspace block reflects the block's linear extrapolation of missing data points at the end of the simulation.
Note A From Workspace block can directly read the output of a To Workspace block (see To Workspace) if the output is in structure-with-time format (see Importing Data from a Workspace for a description of these formats). |
See Importing Data from the MATLAB Workspace for guidelines on choosing time vectors for discrete systems.
The From Workspace block requires data that is the transposition of the data written by the To File block. To provide the required format, use MATLAB commands to load, transpose, and resave the MAT-file. You will then be able to use a From Workspace block to access the data after loading the file to the workspace.
In a To Workspace block, use the Structure with Time format to save sample-based data if you intend to use a From Workspace block to play back the data in another simulation.
The From Workspace block accepts from the workspace and outputs real or complex signals of any type supported by Simulink software, including fixed-point and enumerated data types. Real signals of type double can be in either structure or matrix format. Complex signals and real signals of any type other than double must be in structure format.
The data type of the data supplied by the workspace can affect interpolation and extrapolation of missing values in the following cases.
If the input data type is an integer type and an interpolated data point exceeds the data type's range, the block sets the missing data point to be the maximum value that the data type can represent. Similarly, if the interpolated or extrapolated value is less than the minimum value that the data type can represent, the block sets the missing data point to the minimum value that the data type can represent. For example, suppose that the data type is uint8 and the value interpolated for a missing data point is 256.
time: 1 2 3 4 signal: 253 254 255 ?
In this case, the block sets the value of the missing point to 255, the largest value that can be represented by the uint8 data type:
time: 1 2 3 4 signal: 253 254 255 255
If the input data is boolean, the block uses the value of the nearest workspace data point as the value of missing data point when determining missing data points that fall between the first and last known points. For example, suppose the workspace supplies values at time steps 1 and 4 but not at 2 and 3:
time: 1 2 3 4 signal: 1 ? ? 0
In this case, the block would use the value of data point 1 as the value of data point 2 and the value of data point 4 as the value of data point 3:
time: 1 2 3 4 signal: 1 1 0 0
The block uses the value of the last known data point as the value of time steps that occur after the last known data point.

An expression that evaluates to an array or a structure containing an array of simulation times and corresponding signal values. For example, suppose that the workspace contains a column vector of times named T and a vector of corresponding signal values named U. Entering the expression [T,U] for this parameter yields the required input array. If the required signal-versus-time array or structure already exists in the workspace, enter the name of the structure or matrix in this field.
Sample rate of data from the workspace. See Specifying Sample Time in the online documentation for more information.
This option causes the block to linearly interpolate at time steps for which no corresponding workspace data exists. Otherwise, the current output equals the output at the most recent time for which data exists.
Select to enable zero-crossing detection. For more information, see Zero-Crossing Detection .
Select method for generating output after the last time point for which data is available from the workspace.
Sample Time | Specified in the Sample time parameter |
Scalar Expansion | No |
Dimensionalized | Yes |
Multidimensionalized | Yes |
Zero-Crossing Detection | Yes, if enabled. |
Importing and Exporting Data, From File, To File, To Workspace
![]() | From File | Function-Call Generator | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |