Main Content

From Workspace

Load signal data from workspace into Simulink model

  • Library:
  • Simulink / Sources

  • From Workspace block

Description

The From Workspace block reads data into a Simulink® model from a workspace and provides the data as a signal or bus at the block's output. You can load data from the base workspace, model workspace, or mask workspace. You can use the From Workspace block to load signal data into any model or subsystem in a model hierarchy from a workspace accessible to the referenced model or subsystem.

You can specify how the block constructs the output from the workspace data, including the output sample period, interpolation and extrapolation behavior, and whether to use zero-crossing detection.

The From Workspace block icon shows the value of the Data parameter. For example, if you use the From Workspace block to load data in the variable x, you specify x as the value for the Data parameter, and the block displays x.

Specify Data to Load

Specify data for the From Workspace block to load using the Data parameter. You can specify the value of the Data parameter as a MATLAB® expression, such as a variable name. The expression in the Data parameter must evaluate to data in a format that the From Workspace block supports. For details about how the expression is evaluated, see Symbol Resolution.

The From Workspace block does not load data from a data dictionary. Use a data dictionary to store only design data for a model, not simulation input data. You can store design data related to the From Workspace block, such as the value for the Sample time parameter, in a data dictionary.

Ports

Output

expand all

Data loaded from workspace, provided at the block output as a signal or bus. Depending on the data you load, the output signal may be a scalar, multidimensional, or variable-size signal, a bus, or an array of buses. The From Workspace block supports loading real and complex data of all built-in data types except int64 and uint64.

Data Types: single | double | half | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean | fixed point | enumerated | bus
Complex Number Support: Yes

Parameters

expand all

Data to load from workspace, specified as a variable name or MATLAB expression that evaluates to data in a format supported by the From Workspace block. The expression could create the data the From Workspace block provides at its output, or it could reference a workspace variable that contains the data to load. For more information about how the expression is evaluated, see Symbol Resolution.

The From Workspace block can load data for scalar, multidimensional, and variable-size signals as well as data for a bus or array of buses. The From Workspace block supports loading data in these formats:

  • timeseries object

  • timetable object

  • Simulink.SimulationData.Signal object

  • Structure that represents bus data. The structure hierarchy must match the hierarchy of the bus and use timeseries and timetable objects to represent the signal data.

  • Structure that represents data for a single signal, with fields and hierarchy that match the Structure or Structure with time logging format.

  • Two-dimensional array that represents data for a single signal. The first column in the array represents time and one or more additional columns contain the signal data.

For details, see Load Data Using the From Workspace Block.

When you load data for a bus, specify the Output data type parameter as the Simulink.Bus object that defines the bus.

Real signals of type double can be in any data format that the From Workspace block supports. For complex signals and real signals of a data type other than double, use any format except Array.

The From Workspace block supports loading variable-size signal data in the Structure or Structure with time formats.

Programmatic Use

Block Parameter: VariableName
Type: character vector
Values: MATLAB expression | timeseries object | timetable object | structure | 2-D array
Default: 'simin'

Data type of the workspace data the From Workspace block loads. By default, the From Workspace block inherits the output signal data type from the workspace data or from a downstream block that defines the data type for the signal.

When you load data for a scalar or multidimensional signal, you can choose to inherit the output data type or you can specify the output data type to match the data type of the workspace data.

To load data for a bus or an array of buses, set the Output data type to Bus: <bus_object> and specify the name of the Simulink.Bus object that defines the output bus.

When you load enumerated data, set the Output data type to Enum: <class_name> and specify the name of the enumeration class that defines the enumerated data values.

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant.

Programmatic Use

Block Parameter: OutDataTypeStr
Type: character vector
Values: 'Inherit: auto' | 'double' | 'single' | 'half' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'boolean' | 'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)' | 'Enum: <class name>' | 'Bus: <object name>' | '<data type expression>'
Default: 'Inherit: auto'

The Sample time parameter specifies when the block computes a new output value during simulation. For details, see Specify Sample Time.

Specify the Sample time parameter as a scalar when you do not want the output to have a time offset. To add a time offset to the output, specify the Sample time parameter as a 1-by-2 vector where the first element is the sampling period and the second element is the offset.

By default, the Sample time parameter value is 0, which indicates continuous sample time with no time offset. For a discrete signal, specify the Sample time as the discrete sampling interval. For example, specify the Sample time as 0.1 to model a discrete signal sampled every 100ms. Specify the Sample time as -1 to inherit the value.

Programmatic Use

Block Parameter: SampleTime
Type: character vector
Values: scalar | vector
Default: '0'

Interpolation method used to provide output values for simulation times that are in between time values in the loaded workspace data. When you select Interpolate data, the From Workspace block linearly interpolates an output value using adjacent values in the loaded workspace data. When Interpolate data is not selected, the From Workspace block provides the value of the previous data point in the loaded workspace data. For more information about the interpolation algorithm, see Interpolation.

When you load enumerated, fixed-point, or variable-size signal data, clear the Interpolate data parameter.

To provide output values after the last value in the loaded workspace data, the From Workspace block uses a combination of the Interpolate data parameter and the Form output after final data value by parameter.

The Interpolate data parameter value also affects how the From Workspace block extrapolates output values for simulation times prior to the first data point in the loaded workspace data. When Interpolate data is selected, the From Workspace block uses the first two data points in the workspace data to linearly extrapolate output values for simulation times prior to the first data point. When Interpolate data is not selected, the block provides ground as the output value for simulation times prior to the first workspace data point. For complete information regarding the From Workspace block extrapolation behavior, see Extrapolation.

Programmatic Use

Block Parameter: Interpolate
Type: character vector
Values: 'off' | 'on'
Default: 'on'

Zero-crossing detection is a technique used to locate discontinuities in the block output and avoid using excessively small time steps near the discontinuities, which can slow down a simulation. A zero crossing refers to a discontinuity in the data. You can enable zero-crossing detection for the From Workspace block when the sample time is continuous (0).

The loaded workspace data creates a discontinuity in the block output when the data includes multiple samples with the same time. For example, for this input data, a discontinuity occurs at time 2.

time:     0 1 2 2 3
signal:   2 3 4 5 6

The From Workspace block can also create a discontinuity in the output at the last sample in the workspace data when you set Form output after final data value by to Setting to zero.

When you load input data for a bus, the From Workspace block detects zero crossings for all bus elements.

For more information, see Zero-Crossing Detection.

Programmatic Use

Block Parameter: ZeroCross
Type: character vector
Values: 'off' | 'on'
Default: 'on'

The From Workspace block uses the Interpolate data and Form output after final data value by settings to determine the block output for simulation times after the last sample available in the workspace data.

Setting for Form output after final data value bySetting for Interpolate dataBlock Output After Final Data

Extrapolation

On

Extrapolated from final data value

Off

Error

Setting to zero

On

Zero

Off

Holding final value

On

Final value from workspace

Off

Cyclic repetition

On

Error

Off

When the loaded workspace data uses the structure without time format, repeats workspace data from the first value.

Errors for workspace data formats other than structure with time.

For complete information regarding the From Workspace block extrapolation behavior, see Extrapolation.

Programmatic Use

Block Parameter: OutputAfterFinalValue
Type: character vector
Values: 'Extrapolation' | 'Setting to zero' | 'Holding final value' | 'Cyclic repetition'
Default: 'Extrapolation'

Block Characteristics

Data Types

Boolean | bus | double | enumerated | fixed point[a] | half | integer | single | string

Direct Feedthrough

no

Multidimensional Signals

yes

Variable-Size Signals

yes

Zero-Crossing Detection

yes

[a] Supports input via fi objects created using Fixed-Point Designer.

Tips

  • The From Workspace block supports loading partially specified data for a bus. To partially specify bus data, set bus elements for which you do not need to load data to [].

  • To load data that was logged in array format using the To File block, transpose the array so that the time values are in a single column rather than a single row. You can use the transpose function and save the transposed data to a new file.

  • For programmatic simulations using the sim, parsim, or batchsim functions, you can use the Simulink.SimulationInput object to specify the data for the From Workspace block to load.

Algorithms

expand all

Extended Capabilities

Introduced before R2006a