From Workspace

Load signal data from workspace

  • Library:
  • Simulink / Sources

  • From Workspace block

Description

The From Workspace block reads signal data from a workspace and provides the data at its output as a signal.

The block displays the expression specified in the Data parameter. For details about how the expression gets evaluated, see Symbol Resolution.

You can specify how the data is loaded, including sample time, how to handle data for missing data points, and whether to use zero-crossing detection. For more information, see Load Data Using the From Workspace Block.

Note

Simulink® Coder™ software does not generate code for this block when connected to the Sim port under the conditions listed in Environment Controller.

Specifying Workspace Data

In the From Workspace block dialog box, use the Data parameter to specify the workspace data to load. You can specify a MATLAB® expression (for example, the name of a variable in the MATLAB workspace) that evaluates to one of these options:

  • A timeseries object

  • A structure of timeseries objects

  • A timetable object

  • A structure of timetable objects

  • A structure, with or without time

  • A two-dimensional matrix

For additional information, see Load Data Using the From Workspace Block.

Note

When you specify timetable data to load, each timetable object can contain data for only one signal.

Use with Data Dictionary

When you link a model to a data dictionary, you:

  • Store design data, which contributes to the fundamental design of the model in the Design Data section of the dictionary. Design data includes numeric variables and Simulink.Parameter objects that you use to set block parameter values.

  • Store simulation input data, which you use to stimulate and experiment with the model, in the base workspace. Typically, you create simulation input data as MATLAB timeseries objects.

For more information about storing variables, objects, and other data that a model uses, see Determine Where to Store Variables and Objects for Simulink Models.

  • To access design data by using a From Workspace block, store the target variable in the Design Data section of the dictionary and set the Data parameter of the block to the name of the variable.

  • To access simulation input data, store the target variable in the base workspace and set the Data parameter by using a call to the evalin function. In the call to evalin, specify the ws argument as 'base' so that the block seeks the variable in the base workspace instead of the data dictionary. For example, if the name of the variable is myTimeseriesObject, set Data to evalin('base','myTimeseriesObject').

Ports

Output

expand all

Signal created from workspace data. The block can generate real or complex signals of any type that Simulink supports, including fixed-point and enumerated data types.

Data Types: single | double | half | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus

Parameters

expand all

In the Data parameter, specify the workspace data to load. Specify a MATLAB expression (for example, the name of a variable in the MATLAB workspace) that evaluates to one of the following:

  • A timeseries object

  • A structure of timeseries objects

  • A timetable object

  • A structure of timetable objects

  • A structure, with or without time

  • A two-dimensional matrix

The From Workspace block also accepts a bus object as a data type. To load bus data, use a structure of timeseries or timetable objects. For details, see Load Bus Data to Root-Level Input Ports.

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.

For additional information, see Specify the Workspace Data.

Note

When you specify timetable data to load, each timetable object can contain data for only one signal.

Programmatic Use

Block Parameter: VariableName
Type: character vector
Values: timeseries object | structure of timeseries objects | structure | 2-D matrix
Default: 'simin'

Required data type for the workspace data that the From Workspace block loads. For non-bus types, to skip any data type verification, you can use Inherit: auto. For more information, see Control Signal Data Types.

To load bus data, use a structure of timeseries or timetable objects. For details, see Load Bus Data to Root-Level Input Ports.

Programmatic Use

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

Sample rate of loaded workspace data. For details, see Specify Sample Time.

Programmatic Use

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

When you select this option, the block performs linear interpolation at time hits for which no corresponding workspace data exist. Otherwise, the current output equals the output at the most recent time for which data exists.

The From Workspace block interpolates by using the two corresponding workspace samples:

  • For double data, linearly interpolates the value by using the two corresponding samples

  • For Boolean data, uses false for the first half of the time between two time values and true for the second half

  • For a built-in data type other than double or Boolean:

    • Upcasts the data to double

    • Performs linear interpolation (as described for double data)

    • Downcasts the interpolated value to the original data type

You cannot use linear interpolation with enumerated (enum) data.

The block uses the value of the last known data point as the value of time hits that occur after the last known data point.

To determine the block output after the last time hit for which workspace data is available, combine the settings of these parameters:

  • Interpolate data

  • Form output after final data value by

For details, see the Form output after final data value by parameter.

Programmatic Use

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

When you select Enable zero-crossing detection, and the input array contains multiple entries for the same time hit, Simulink detects a zero crossing. For example, suppose that 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. For more information, see Zero-Crossing Detection.

For bus signals, Simulink detects zero crossings across all leaf bus elements.

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 after the last sample available in the workspace data.

This table lists the block output, based on the values of the two options.

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

Repeated from workspace if the workspace data is in structure-without-time format. Error otherwise.

For example, when you enable Interpolate data and set Form output after final data value by to Extrapolation, the block uses the last two data points in the workspace data to extrapolate values for subsequent data points.

For example, consider this model. The From Workspace block reads workspace data that was created by logging the output of the Sine Wave block for a 16-second simulation. The Dashboard Scope blocks display the Sine Wave block output and From Workspace block output for a 20-second simulation. After the simulation reaches 16 seconds, the From Workspace block output diverges from the Sine Wave block output as the From Workspace block linearly extrapolates values for the remainder of the simulation.

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.

Extended Capabilities

Introduced before R2006a