| Contents | Index |
Sinks
The To Workspace block inputs a signal and writes the signal data to the MATLAB workspace. During the simulation, the block writes data to an internal buffer. When the simulation is completed or paused, that data is written to the workspace. The block icon shows the name of the array to which the data is written.
To specify the name of the workspace variable to which the To Workspace block writes the data, use the Variable name parameter. To specify the data format of the variable, use the Save format parameter. You can specify to save the data in one of the following formats:
A MATLAB timeseries object (or structure of MATLAB timeseries objects for bus data)
An array
Structure
Structure with time
To use a From Workspace block to play back the sample-based data that was saved by a To Workspace block in a previous simulation, in the To Workspace block, use the Timeseries or Structure with time format.
For variable-step solvers, to control the amount of data available to the To Workspace block, use the Configuration Parameters > Data Import/Export > Output options parameter. For example, have Simulink writes data at identical time points over multiple simulations, select the Produce specified output only option.
Then use To Workspace block parameters to control when and how much of this data the block writes:
Use the Limit data points to last parameter to specify how many sample points to save. If the simulation generates more data points than the specified maximum, the simulation saves only the most recently generated samples. To capture all the data, set this value to inf.
Use the Decimation parameter to have the To Workspace block write data at every nth sample, where n is the decimation factor. The default decimation, 1, writes data at every time step.
Use the Sample time parameter to specify a sampling interval at which to collect points. This parameter is useful when you are using a variable-step solver where the interval between time steps might not be the same. The default value of -1 causes the block to inherit the sample time from the driving block when determining the points to write. See How to Specify the Sample Time in the online documentation for more information.
For example, suppose you have a simulation where the start time is 0, the Limit data points to last is 100, the Decimation is 1, and the Sample time is 0.5. The To Workspace block collects a maximum of 100 points, at time values of 0, 0.5, 1.0, 1.5, ..., seconds. Specifying a Decimation value of 1 directs the block to write data at each step.
In a similar example, the Limit data points to last is 100 and the Sample time is 0.5, but the Decimation is 5. In this example, the block collects up to 100 points, at time values of 0, 2.5, 5.0, 7.5, ..., seconds. Specifying a Decimation value of 5 directs the block to write data at every fifth sample. The sample time ensures that data is written at these points.
In another example, all parameters are as defined in the first example except that the Limit data points to last is 3. In this case, only the last three sample points collected are written to the workspace. If the simulation stop time is 100, data corresponds to times 99.0, 99.5, and 100.0 seconds (three points).
If you enable the Configuration Parameters > Code Generation > MAT-file logging parameter, then To Workspace logs its data to a MAT-file.
The To Workspace block can save to the MATLAB workspace real or complex inputs of any data type that Simulink supports, including fixed-point and enumerated data types, as well as bus objects.
For more information, see Data Types Supported by Simulink in the Simulink documentation.

Specify the name of the variable to which to save the data.
Specify the maximum number of input samples to save. The default is inf.
Specify the decimation factor. The default is 1.
Specify the sample period and offset at which to collect data. This parameter is useful when you are using a variable-step solver where the interval between time steps might not be constant. The default is-1, which inherits the sample time from the driving block. See How to Specify the Sample Time for more information.
Specify one of these formats for saving simulation output to the workspace:
Timeseries — (Default)
Save non-bus signal input as a MATLAB timeseries object and bus signal input as a structure of MATLAB timeseries objects.
Array
Save the input as an N-dimensional array where N is one more than the number of dimensions of the input signal. For example, if the input signal is a a vector, the resulting workspace array is two-dimensional. If the input signal is a matrix, then the array is three-dimensional.
How Simulink stores samples in the array depends on whether the input signal is a scalar or vector or a matrix. If the input is a scalar or a vector, each input sample is output as a row of the array. For example, suppose that the name of the output array is simout. Then, simout(1,:) corresponds to the first sample, simout(2,:) corresponds to the second sample, and so on. If the input signal is a matrix, the third dimension of the workspace array corresponds to the values of the input signal at specified sampling point. For example, suppose again that simout is the name of the resulting workspace array. Then, simout(:,:,1) is the value of the input signal at the first sample point; simout(:,:,2) is the value of the input signal at the second sample point; and so on.
Structure
This format consists of a structure with three fields:
time — This field is empty for this format.
signals — A structure with three fields: values, dimensions, and label. The values field contains the array of signal values. The dimensions field specifies the dimensions of the values array. The label field contains the label of the input line.
blockName — Name of the To Workspace block
Structure With Time
This format is the same as Structure, except that the time field contains a vector of simulation time steps.
To read To Workspace block output directly with a From Workspace block, use either the Timeseries or Structure with Time format. For details, see Importing Signal Data in Simulink.
Structure with Time format does not support frame-based signals. Use Array or Structure format instead.
The support for simulation modes varies for the Timeseries format and non-Timeseries formats (Array, Structure, and Structure With Time).
| Simulation Mode | Timeseries Format | Non-Timeseries Formats |
|---|---|---|
| Normal | Supported | Supported |
| Accelerator | Supported for all models, including model references | Supported for models without model references |
| Rapid Accelerator | Not supported | Supported for models without model references |
| External mode | Not supported | Supported for models without model references |
| SIL and PIL | Not supported | Supported for models without model references |
| Simulink Coder Targets | Not supported | Supported for models without model references |
Select to log fixed-point data to the MATLAB workspace as a Simulink Fixed-Point fi object. Otherwise, fixed-point data is logged to the workspace as double.
The following demos show how to use the To Workspace block:
Sample Time | Specified in the Sample time parameter |
Dimensionalized | Yes |
Multidimensionalized | Yes |
Importing and Exporting Simulation Data, From File, From Workspace, To File

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |