Documentation

From Spreadsheet

Read data from spreadsheet

Library

Sources

Description

The From Spreadsheet block reads data from Microsoft® Excel® (all platforms) or CSV (Microsoft Windows® platform with Microsoft Office installed only) spreadsheets and outputs the data as a signal.

The From Spreadsheet icon displays the spreadsheet file name and sheet name specified in the block File name and Sheet name parameters.

Storage Formats

The data that the From Spreadsheet block reads from a spreadsheet must be appropriately formatted.

For Microsoft Excel spreadsheets:

  • The From Spreadsheet block interprets the first row as a signal name. If you do not specify a signal name, the From Spreadsheet block assigns a default one with the format Signal #, where # increments with each additional unnamed signal.

  • The From Spreadsheet block interprets the first column as time. In this column, the time values must monotonically increase.

  • The From Spreadsheet block interprets the remaining columns as signals.

This example shows an acceptably formatted Microsoft Excel spreadsheet. The first column is Time and the first row contains signal names. Each worksheet contains a signal group.

For CSV text files (Microsoft platform with Microsoft Office installed only):

  • The From Spreadsheet block interprets the first column as time. In this column, the time values must increase.

  • The From Spreadsheet block interprets the remaining columns as signals.

  • Each column must have the same number of entries.

  • The From Spreadsheet block interprets each file as one signal group.

This example shows an acceptably formatted CSV file. The contents represent one signal group.

0,0,0,5,0
1,0,1,5,0
2,0,1,5,0
3,0,1,5,0
4,5,1,5,0
5,5,1,5,0
6,5,1,5,0
7,0,1,5,0
8,0,1,5,1
9,0,1,5,1
10,0,1,5,0

Block Behavior During Simulation

The From Spreadsheet block incrementally reads data from the spreadsheet during simulation.

The Sample time parameter specifies the sample time that the From Spreadsheet block uses to read data from the spreadsheet. For details, see Parameters. The time stamps in the file must be monotonically nondecreasing.

For each simulation time hit for which the spreadsheet contains no matching time stamp, Simulink® software interpolates or extrapolates to obtain the needed data using the selected method. For details, see Simulation Time Hits That Have No Corresponding Spreadsheet Time Stamps.

Simulation Time Hits That Have No Corresponding Spreadsheet Time Stamps

If the simulation time hit does not have a corresponding spreadsheet time stamp, the From Spreadsheet block output depends on:

  • Whether the simulation time hit occurs before the first time stamp, within the range of time stamps, or after the last time stamp

  • The interpolation or extrapolation methods that you select

  • The data type of the spreadsheet data

For details about interpolation and extrapolation options, see the descriptions of the following parameters in “Parameters and Dialog Box”:

  • Data extrapolation before first data point

  • Data interpolation within time range

  • Data extrapolation after last data point

Sometimes the spreadsheet includes two or more data values that have the same time stamp. In such cases, the From Spreadsheet block action depends on when the simulation time hit occurs, relative to the duplicate time stamps in the spreadsheet.

For example, suppose that the spreadsheet contains this data. Three data values have a time stamp value of 2.

time stamps:    0 1 2 2 2 3 4
data values:    2 3 6 4 9 1 5

The table describes the From Spreadsheet block output.

Simulation Time, Relative to Duplicate Time Stamp Values in SpreadsheetFrom Spreadsheet Block Action
Before the duplicate time stamps

Performs the same actions as when the time stamps are distinct, using the first of the duplicate time stamp values as the basis for interpolation. (In this example, the time stamp value is 6.)

At or after the duplicate time stamps

Performs the same actions as when the times stamps are distinct, using the last of the duplicate time stamp values as the basis for interpolation. (In this example, that time stamp value is 9.)

Rounding Mode

The From Spreadsheet block rounds positive and negative numbers toward negative infinity. This mode is equivalent to the MATLAB® floor function.

Saturation on Integer Overflow

For data type conversion, the From Spreadsheet block deals with saturation overflow by wrapping to the appropriate value that the data type can represent. For example, the number 130 does not fit in a signed 8-bit integer and wraps to –126.

Code Generation Requirements

Simulating in accelerator, rapid accelerator, model reference accelerator mode, or model reference rapid accelerator mode behaves the same way, and has the same requirements, as simulating in normal mode.

The From Spreadsheet block does not support generating code that involves building ERT or GRT targets, or using SIL or PIL simulation modes.

Data Type Support

The From Spreadsheet block supports these data types:

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

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

The From Spreadsheet block accepts data type specifications at a block level.

If you want to specify different data types for each signal, consider selecting Output Data Type > Inherit: Auto. This option resolves back signal data types using back propagation. For example, assume that there are two signals in the From Spreadsheet block, In1 and In2, which the block sends to ports that have int8 and Boolean data types. With back propagation, the block recasts In1 as int8 and In2 as boolean.

Parameters

File name

Enter full path and file name of a spreadsheet file.

This block supports non-English full paths and file names only on Microsoft platforms.

Settings

Default: untitled.xlsx

Command-Line Information

FileName

character vector

Sheet name

Enter the name of the sheet in the spreadsheet. You can type the sheet name in this edit box, or select the sheet name after you open the sheet.

To open the sheet, click . In the sheet, you can select the range of data by dragging over the desired range of values.

Alternatively, you can select the range of data by specifying the range of values in the Range parameter.

Settings

Default: Sheet1

Command-Line Information

SheetName

character vector

Range

To specify the range, use the format column:row, with multiple specifications separated by commas. For example, A1:B3,D1:D3,A7:B9,D7:D9. If unspecified, or empty, the block automatically detects the used range, which is all the data in the sheet.

If the selections overlap, the block resolves the selection information as appropriate. For example, if you specify multiple ranges that overlap, such as A1:B4,B1:E7, the block resolves the selection to A1 to E7, inclusive.

Settings

Default: Empty

Command-Line Information

Range

character vector

Output data type

The data type for the From Spreadsheet block output. The From Spreadsheet block accepts spreadsheets that contain many data types. However, the block reads the spreadsheet data type as doubles. It then outputs the data type according to the value of Output data type.

To allow the block to cast the output data type to match that of the receiving block, use Inherit: auto.

For more information, see Control Signal Data Types.

Settings

Default: Inherit: auto

Cast output data type to match that of the receive block.

Inherit: auto

Cast output data type to match that of the receive block.

double

Output data type is double.

single

Output data type is single.

int8

Output data type is int8.

uint8

Output data type is uint8.

int16

Output data type is int16.

uint16

Output data type is uint16.

int32

Output data type is int32.

uint32

Output data type is uint32.

boolean

Output data type is boolean.

fixdt(1,16,0)

Output data type is fixed point fixdt(1,16,0).

fixdt(1,16,2^0,0)

Output data type is fixed point fixdt(1,16,2^0,0).

Enum: <class name>

Output data type is enumerated, for example, Enum: Basic Colors.

<data type expression>

The name of a data type object, for example Simulink.NumericType

Command-Line Information

OutDataTypeStr

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>'

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

Settings

Default: Inherit

Inheritance rule for data types. Selecting Inherit enables a second menu/text box to the right.

  • Inherit

    Inheritance rule for data types. Selecting Inherit enables a second menu/text box to the right.

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

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

Data type override

Specify data type override mode for this signal.

Settings

Default: Inherit

Inherit

Inherits the data type override setting from its context, that is, from the block, Simulink.Signal object or Stateflow® chart in Simulink that is using the signal.

Off

Ignores the data type override setting of its context and uses the fixed-point data type specified for the signal.

Tip

The ability to turn off data type override for an individual data type provides greater control over the data types in your model when you apply data type override. For example, you can use this option to ensure that data types meet the requirements of downstream blocks regardless of the data type override setting.

Dependency

This parameter appears only when the Mode is Built in or Fixed point.

Signedness

Specify whether you want the fixed-point data as signed or unsigned.

Settings

Default: Signed

Signed

Specify the fixed-point data as signed.

Unsigned

Specify the fixed-point data as unsigned.

Dependencies

Selecting Mode > Fixed point enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Word length

Specify the bit size of the word that holds the quantized integer.

Settings

Default: 16

Minimum: 0

Maximum: 32

Dependencies

Selecting Mode > Fixed point enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Scaling

Scaling

Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.

Settings

Default: Binary point

Binary point

Specify binary point location.

Slope and bias

Enter slope and bias.

Dependencies

Selecting Mode > Fixed point enables this parameter.

Selecting Binary point enables:

  • Fraction length

  • Calculate Best-Precision Scaling

Selecting Slope and bias enables:

  • Slope

  • Bias

  • Calculate Best-Precision Scaling

Fraction length

Specify fraction length for fixed-point data type.

Settings

Default: 0

Binary points can be positive or negative integers.

Dependencies

Selecting Scaling > Binary point enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Slope

Specify slope for the fixed-point data type.

Settings

Default: 2^0

Specify any positive real number.

Dependencies

Selecting Scaling > Slope and bias enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Bias

Specify bias for the fixed-point data type.

Settings

Default: 0

Specify any real number.

Dependencies

Selecting Scaling > Slope and bias enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Treat first column as

Select how the block should treat the first column of the spreadsheet:

  • Time — Treat first column as time.

  • Data — Treat first column as data. Selecting this option disables:

    • Data extrapolation before first data point

    • Data interpolation within time range

    • Data extrapolation after last data point

  • Selecting this option enables Output after last data point.

Sample time

The sample period and offset.

The From Spreadsheet block reads data from a spreadsheet using a sample time that either:

  • You specify for the From Spreadsheet block

  • The From Spreadsheet block inherits from the blocks into which the From Spreadsheet block feeds data

The default is 0, which specifies a continuous sample time. The spreadsheet is read at the base (fastest) rate of the model. For details, see Specify Sample Time.

Command-Line Information

SampleTime

character vector — {'0'}

Data extrapolation before first data point

Extrapolation method that Simulink uses for a simulation time hit that is before the first time stamp in the spreadsheet. Choose one of the following extrapolation methods.

MethodDescription
Linear extrapolation

(Default)

If the spreadsheet contains only one sample, the From Spreadsheet block outputs the corresponding data value.

If the spreadsheet contains more than one sample, the From Spreadsheet block linearly extrapolates using the first two samples:

  • For double data, linearly extrapolates the value using the first two samples

  • For Boolean data, outputs the first data value

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

    • Upcasts the data to double.

    • Performs linear extrapolation (as described above for double data).

    • Downcasts the extrapolated data value to the original data type.

You cannot use the Linear extrapolation option with enumerated (enum) data.

Hold first value

Uses the first data value in the file

Ground value

Uses a value that depends on the data type of spreadsheet sample data values:

  • Fixed-point data types — Uses the ground value

  • Numeric types other than fixed–point — Uses 0

  • Boolean — Uses false

  • Enumerated data types — Uses default value

Command-Line Information

ExtrapolationBeforeFirstDataPoint

character vector — {'Linear extrapolation'} | 'Hold first value' | 'Ground value'

Data interpolation within time range

The interpolation method that Simulink uses for a simulation time hit between two time stamps in the spreadsheet. Choose one of the following interpolation methods.

MethodDescription
Linear interpolation

(Default)

The From Spreadsheet block interpolates using the two corresponding spreadsheet samples:

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

  • For Boolean data, uses false for the first half of the sample 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 above for double data).

    • Downcasts the interpolated value to the original data type.

You cannot use the Linear interpolation option with enumerated (enum) data.

Zero order hold

Uses the data from the first of the two samples

Command-Line Information

InterpolationWithinTimeRange

character vector — {'Linear interpolation'} | 'Zero order hold'

Data extrapolation after last data point

The extrapolation method that Simulink uses for a simulation time hit that is after the last time stamp in the spreadsheet. Choose one of the following extrapolation methods.

MethodDescription
Linear extrapolation

(Default)

If the spreadsheet contains only one sample, the From Spreadsheet block outputs the corresponding data value.

If the spreadsheet contains more than one sample, the From Spreadsheet block linearly extrapolates using data values of the last two samples:

  • For double data, extrapolates the value using the last two samples

  • For Boolean data, outputs the last data value

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

    • Upcasts the data to double.

    • Performs linear extrapolation (as described above for double data).

    • Downcasts the extrapolated value to the original data type.

You cannot use the Linear extrapolation option with enumerated (enum) data.

Hold last value

Uses the last data value in the file

Ground value

Uses a value that depends on the data type of spreadsheet sample data values:

  • Fixed-point data types — uses the ground value

  • Numeric types other than fixed–point — uses 0

  • Boolean — uses false

  • Enumerated data types — uses default value

Command-Line Information

ExtrapolationAfterLastDataPoint

character vector — {'Linear extrapolation'} | 'Hold last value' | 'Ground value'

Output after last data point

Select action after last data point:

  • Repeat sequence — Repeat the sequence by reading the data from the first row of the range specified in Range (default)

  • Hold final value — Output the last defined value for the remainder of the simulation.

  • Ground value — Output a ground value depending on the data type value specified in Output data type.

Enable zero-crossing detection

Select to enable zero-crossing detection.

The Zero-Crossing Detection parameter applies only if the Sample time parameter is set to 0 (continuous).

Simulink uses a technique known as zero-crossing detection to locate accurately a discontinuity, without resorting to excessively small time steps. This section uses “zero-crossing” to represent discontinuities.

For the From Spreadsheet block, zero-crossing detection can only occur at time stamps in the file. Simulink examines only the time stamps, not the data values.

If the input array contains duplicate time stamps (more than one entry with the same time stamp), Simulink detects a zero crossing at that time stamp. 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 the input signal discontinuity.

For data with nonduplicate time stamps, zero-crossing detection depends on the settings of the following parameters:

  • Data extrapolation before first data point

  • Data interpolation within time range

  • Data extrapolation after last data point

The block applies the following rules when determining when:

  • Zero-crossing occurs for the first time stamp.

  • For time stamps between the first and last time stamp.

  • For the last time stamp.

Time StampWhen Zero-Crossing Detection Occurs

First

Data extrapolation before first data point is set to Ground value.

Between first and last

Data interpolation within time range is set to Zero-order hold.

Last

One or both of these settings occur:

  • Data extrapolation after last data point is set to Ground value.

  • Data interpolation within time range is set to Zero-order hold.

The following figure illustrates zero-crossing detection for data accessed by a From Spreadsheet block that has the following settings:

  • Data extrapolation before first data pointLinear extrapolation

  • Data interpolation within time range (for internal points) — Zero order hold

  • Data extrapolation after last data pointLinear extrapolation

The following figure is another illustration of zero-crossing detection for data accessed by a From Spreadsheet block. The block has the following settings for the time stamps (points):

  • Data extrapolation before first data pointHold first value

  • Data interpolation within time rangeZero order hold

  • Data extrapolation after last data pointHold last value

Command-Line Information

ZeroCross

character vector — 'off' | {'on'}

Characteristics

Data Types

Specified in Data Type Support

Sample Time

Specified in the Sample time parameter

Multidimensional Signals

No

Variable-Size Signals

No

Zero-Crossing Detection

Yes

Code Generation

No

See Also

Introduced in R2015b

Was this topic helpful?