Skip to Main Content Skip to Search
Product Documentation

To Workspace - Write data to MATLAB workspace

Library

Sinks

Description

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:

Saving Data for Use by a From Workspace Block

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.

Controlling the Amount of Data Saved

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:

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).

MAT-File Logging

If you enable the Configuration Parameters > Code Generation > MAT-file logging parameter, then To Workspace logs its data to a MAT-file.

Data Type Support

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.

Parameters and Dialog Box

Variable name

Specify the name of the variable to which to save the data.

Limit data points to last

Specify the maximum number of input samples to save. The default is inf.

Decimation

Specify the decimation factor. The default is 1.

Sample time

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.

Save format

Specify one of these formats for saving simulation output to the workspace:

The support for simulation modes varies for the Timeseries format and non-Timeseries formats (Array, Structure, and Structure With Time).

Simulation ModeTimeseries Format Non-Timeseries Formats
NormalSupportedSupported
AcceleratorSupported for all models, including model referencesSupported for models without model references
Rapid AcceleratorNot supportedSupported for models without model references
External modeNot supportedSupported for models without model references
SIL and PILNot supportedSupported for models without model references
Simulink Coder TargetsNot supportedSupported for models without model references

Log fixed-point data as a fi object

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.

Examples

The following demos show how to use the To Workspace block:

Characteristics

Sample Time

Specified in the Sample time parameter

Dimensionalized

Yes

Multidimensionalized

Yes

See Also

Importing and Exporting Simulation Data, From File, From Workspace, To File

  


Related Products & Applications

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