DSP Blockset | ![]() ![]() |
Write simulation data to an array in the MATLAB main workspace.
Library
Description
The Signal To Workspace block writes data from your simulation into an array in the MATLAB main workspace. The output array can be 2-D or 3-D, depending on whether the data is 1-D, sample-based, or frame-based. The Signal To Workspace block and the Simulink To Workspace block can output the same arrays if their parameters are set appropriately.
For more information on the Signal To Workspace block, see the following sections of this reference page:
Parameter Descriptions
The Variable name parameter is the name of the array in the MATLAB workspace into which the block logs the simulation data. The array is created in the workspace only after the simulation stops running. If you enter the name of an existing workspace variable, the block overwrites the variable with an array of simulation data after the simulation stops running.
When the block input is sample-based or 1-D, the Limit data points to last parameter indicates how many samples of data to save. If the block input is frame-based, this parameter indicates how many frames of data to save. If the simulation generates more than the specified maximum number of samples or frames, the simulation saves only the most recently generated data. To capture all data, set Limit data points to last to inf
.
The Decimation parameter is the decimation factor. It can be set to any positive integer d, and allows you to write data at every dth sample. The default decimation, 1
, writes data at every time step.
The Frames parameter sets the dimension of the output array to 2-D or 3-D for frame-based inputs. The block ignores this parameter for 1-D and sample-based inputs. The Frames parameter has the following two settings:
Signal to Workspace always logs sample-based input data as 3-D arrays, regardless of the Frame parameter setting. Given an M-by-N sample-based signal, the block outputs an M-by-N-by-L array, where L is the number of samples logged by the end of the simulation (L is bounded above by the Limit data points to last parameter). Each sample-based matrix is an element of the 3-D array. (See Example 1: Sample-Based Inputs.)
For 1-D vector inputs, the block outputs a 2-D matrix regardless of the setting of Frame. For a length-N 1-D vector input, the block outputs an L-by-N matrix. Each input vector is a row of the output matrix, vertically concatenated to the previous vector.
Output Dimension Summary
The following table summarizes the output array dimensions for various block inputs. In the table, f is the frame size of the input, K is the number of frames acquired by the end of the simulation, and L is the number of samples acquired by the end of the simulation (K and L are bounded above by the Limit data points to last parameter).
Matching the Outputs of Signal To Workspace and To Workspace Blocks
The To Workspace block in the Simulink Sinks Library and the Signal To Workspace block can output the same array if they are given the same inputs. To match the blocks' outputs, set their parameters as follows.
Examples
Example 1: Sample-Based Inputs. In the following Example 1 model, the input to the Signal To Workspace block is a 2-by-2 sample-based matrix signal with a sample time of 1 (generated by a Signal From Workspace block). The Signal To Workspace block logs 11 samples by the end of the simulation, and creates a 2-by-2-by-11 array, A, in the MATLAB workspace.
The Example 1 block settings are as follows.
input1 = cat(3, [1 1; -1 0], [2 1; -2 0],...,[11 1; -11 0])
Example 2: Frame-Based Inputs. In the following Example 2 model, the input to the Signal To Workspace block is a 2-by-4 frame-based matrix signal with a frame period of 1 (generated by a Signal From Workspace block). The block logs 11 frames (two samples per frame) by the end of the simulation. The frames are concatenated to create a 22-by-4 matrix, A, in the MATLAB workspace.
The block settings for the following Example 2 model are similar to the Example 1 block settings, except Frames is set to Concatenate frames (2-D array) and the Signal From Workspace parameter, Signal, is set to input2
, where
input2 = [1 -1 1 0; 2 -2 1 0; 3 -3 1 0;...; 22 -22 1 0]
In the 2-D output, there is no indication of where one frame ends and another begins. By setting Frames to Log frames separately (3-D array) in the Example 2 model, you can easily see each frame in the MATLAB workspace, as illustrated in the following model. Each of the 11 frames is logged separately to create a 2-by-4-by-11 array, A, in the MATLAB workspace.
Dialog Box
Supported Data Types
To learn how to convert to the above data types in MATLAB and Simulink, see Supported Data Types and How to Convert to Them.
See Also
Triggered To Workspace |
DSP Blockset |
To Workspace |
Simulink |
Also see DSP Sinks for a list of all the blocks in the DSP Sinks library.
![]() | Signal From Workspace | Sine Wave | ![]() |