Documentation

From Workspace

Load signal data from workspace

Library

Sources

Description

The From Workspace block reads signal data from a workspace and outputs the data as a signal.

The From Workspace icon displays the expression specified in the Data parameter. For details about how Simulink® software evaluates this expression, 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.

Specifying the Workspace Data

In the Block Parameters dialog box of the From Workspace block, 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 MATLAB timeseries object

  • A structure of MATLAB timeseries objects

  • A structure, with or without time

  • A two-dimensional matrix

For additional information, see Create Data for a From Workspace Block.

Data Type Support

The From Workspace block accepts data from the workspace. The block outputs real or complex signals of any type that Simulink supports, including fixed-point and enumerated data types.

The From Workspace block also accepts a bus object as a data type. To load bus data, use a structure of MATLAB timeseries objects. For details, see Import Bus Data to Top-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 Create Data for a From Workspace Block.

Parameters

Data

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 MATLAB timeseries object

  • A structure of MATLAB timeseries objects

  • A structure, with or without time

  • A two-dimensional matrix

For additional information, see Specify the Workspace Data.

Command-Line Information

Parameter: VariableName
Type: character vector
Default: 'simin'

Output data type

The required data type for the data for the workspace variable 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 MATLAB timeseries objects. For details, see Import Bus Data to Top-Level Input Ports.

  • Inherit: auto — Default.

  • double

  • single

  • int8

  • uint8

  • int16

  • uint16

  • int32

  • uint32

  • boolean

  • fixdt(1,16,0) — Data type is fixed point (1,16,0).

  • fixdt(1,16,2^0,0) — Data type is fixed point (1,16,2^0,0).

  • Enum: <class_name> — Data type is enumerated, for example, Enum: Basic Colors.

  • Bus: <bus_object> — Data type is a bus object.

  • <data type expression> — The name of a data type object, for example Simulink.NumericType. Do not specify a bus object as the expression.

Command-Line Information

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

>> (Show data type assistant)

Displays the Data Type Assistant, to help you to set the Output data type parameter.

Mode

The category of data to specify. For more information, see Control Signal Data Types.

  • Inherit — Inheritance rule for data types. Selecting Inherit enables a second menu/text box to the right. (Default)

  • Built in — Built-in data types. Selecting Built in enables a second menu/text box to the right. Select one of the following choices:

    • double — Default

    • single

    • int8

    • uint8

    • int16

    • uint16

    • int32

    • uint32

    • boolean

    • Fixed point — Fixed-point data types

    • Enumerated — Enumerated data types. Selecting Enumerated enables a second menu/text box to the right, where you can enter the class name.

    • Bus — Bus object. Selecting Bus enables a Bus object parameter, where you enter the name of a bus object that you want to use to define the structure of the bus. To create or change a bus object, click Edit (to the right of the Bus object field) to open the Simulink Bus Editor. For details, see Create Bus Objects with the Bus Editor.

    • Expression — Expression that evaluates to a data type. Selecting Expression enables a second menu/text box to the right, where you enter the expression. Do not specify a bus object as the expression.

Sample time

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

Command-Line Information

Parameter: SampleTime
Type: character vector
Default: '0'

Interpolate data

To have the block linearly interpolate at time hits for which no corresponding workspace data exist, select this option. 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.

Command-Line Information

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

Enable zero-crossing detection

If you select the Enable zero-crossing detection parameter, then when 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.

Command-Line Information

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

Form output after final data value by

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

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

Zero

Holding final value

On

Final value from workspace

Off

Final value from workspace

Cyclic repetition

On

Error

Off

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

For example, the block uses the last two known data points to extrapolate data points that occur after the last known point if you:

  • Select Interpolate data.

  • Set Form output after final data value by to Extrapolation.

Consider this model.

The From Workspace block reads data from the workspace. The data consists of the output of the Simulink Sine block sampled at one-second intervals. The workspace contains the first 16 samples of the output. The top and bottom X-Y plots display the output of the Sine Wave and From Workspace blocks, respectively, from 0 to 20 seconds. The straight line in the output of the From Workspace block reflects the linear extrapolation of missing data points at the end of the simulation.

Command-Line Information

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

Examples

With the From Workspace block, you can read 1-D and 2-D signals into Simulink. The From Workspace block does not read n-D signals into Simulink.

Read 1-D Signals in Array Format

Create two signals x and y with a time vector t. Import the values into Simulink with an array.

  1. In the MATLAB Command Window, enter:

    t = 0.2 * [0:49]';
    x = sin(t);
    y = 10*sin(t);

    The time vector must be a column vector.

  2. Add a From Workspace block to your model.

  3. For the From Workspace block, in Data parameter, enter the array [t,x,y].

Read 1-D Signals in Structure Format

Create two signals x and y with a time vector t. Import the values into Simulink with a structure.

  1. In the MATLAB Command Window, enter:

    t = 0.2 * [0:49]';
    x = sin(t);
    y = 10*sin(t);
    wave.time = t;
    wave.signals.values = [x,y];
    wave.signals.dimensions =2;

    The time vector must be a column vector. The signals.dimensions field for the signal is a scalar corresponding to the number of columns in the signals.values field.

  2. Add a From Workspace block to your model.

  3. In the From Workspace block parameters dialog box, in the Data field, enter the structure name.

Use Sample Time from Model

If you do not have a time vector, you can define the sample time in your model.

  1. In the MATLAB Command Window, enter

    wave.time = [];

  2. In the From Workspace block parameters dialog box, in the Sample time field, enter a time interval. For example, enter 0.2. Clear the Interpolate data check box.

  3. In the Form output after final data value by, select Setting to zero, Holding final value, or Cyclic repetition. Do not select Extrapolation.

Read 2-D Signals in Structure Format

To load 2-D signals from the MATLAB workspace into Simulink, you must have the signals in a structure format. This example creates a 10–by–10 matrix (2-D signal) by using the magic function, and then creates a 3-D matrix by adding a time vector.

  1. In the MATLAB Command Window, enter:

    t1 = 0.2 * [0:49]';
    m = magic(10);
    M = repmat(m,[1 1 length(t1)]);
    data.time=t1;
    data.signals.values = M;
    data.signals.dimensions=[10 10];

    The time vector must be a column vector. The signals.values field is a 3-D matrix where the third dimension corresponds to time. The signals.dimensions field is a two-element vector. The first element is the number of rows and the second element is the number of columns in the signals.values field.

  2. In the From Workspace block parameters dialog box, in the Data field, enter the name of the structure.

Characteristics

Data Types

Double | Single | Boolean | Base Integer | Fixed-Point | Enumerated | Bus

Sample Time

Specified in the Sample time parameter

Multidimensional Signals

Yes

Variable-Size Signals

Yes

Zero-Crossing Detection

Yes, if enabled

Code Generation

No

Introduced before R2006a

Was this topic helpful?