From File

Load data from MAT-file

  • Library:
  • Simulink / Sources

  • From File block

Description

The From File block loads data from a MAT-file into a model and outputs the data as a signal. The data is a sequence of samples. Each sample consists of a time stamp and an associated data value. The data can be in array format or MATLAB® timeseries format.

The From File block icon shows the name of the MAT-file that supplies the data to the block.

You can have multiple From File blocks that load from the same MAT-file.

The supported MAT-file versions are Version 7.0 or earlier and Version 7.3. The From File block incrementally loads data from Version 7.3 files.

You can specify how the data is loaded, including:

  • Sample time

  • How to handle data for missing data points

  • Whether to use zero-crossing detection

For more information, see Load Data Using the From File Block.

Ports

Output

expand all

MAT-file data, specified as a sequence of samples. Each sample consists of a time stamp and an associated data value. The data can be in array format or MATLAB timeseries format. When you load timeseries data using the From File block, the data type of the time data must be double.

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

Parameters

expand all

Path or file name of the MAT-file that contains the input data. Specify a path or file name in one of these ways:

  • Browse to a folder that contains a valid MAT-file.

    On UNIX® systems, the path name can start with a tilde (~) character, which means your home folder.

  • Enter the path for the file in the text box.

The default file name is untitled.mat. If you specify a file name without path information, Simulink® loads the file in the current folder or on the MATLAB path. (To determine the current folder, at the MATLAB command prompt enter pwd.)

After you specify the File name, you can use the view button () to preview the signal from the MAT-file. For more information, see Preview Signal Data.

Dependencies

Code generation for RSim target provides identical support as Simulink; all other code generation targets support only double, one-dimensional, real signals in array with time format.

To generate code that builds ERT or GRT targets or uses SIL or PIL simulation modes, the MAT-file must contain a nonempty, finite, real matrix with at least two rows.

For more information on C/C++ code generation with the From File block, see Code Generation.

Programmatic Use

Block Parameter: FileName
Type: character vector
Values: MAT-file name
Default: 'untitled.mat'

The data type for the data that the From File block outputs. For nonbus types, you can use Inherit: auto to skip any data type verification. If you specify an output data type, then the From File block verifies that the data in the file matches the specified data type. For more information, see Control Signal Data Types.

If you set Output data type as a bus object, the bus object must be available when you compile the model. For each signal in bus data, the From File block verifies that data type, dimensions, and complexity are the same for the data and for the bus object.

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

Specify the sample period and offset.

The From File block loads data from a MAT-file, using a sample time that either:

  • You specify for the From File block.

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

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

Programmatic Use

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

Extrapolation method for a simulation time hit that occurs before the initial time stamp in the MAT-file. Choose one of the following extrapolation methods.

MethodDescription
Linear extrapolation

(Default)

If the MAT-file contains only one sample, then the From File block outputs the corresponding data value.

If the MAT-file contains more than one sample, then the From File 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, the From File block:

    • Upcasts the data to double

    • Performs linear extrapolation (as described for double data)

    • Downcasts the extrapolated data value to the original data type

You cannot use the Linear extrapolation option with enumerated (enum) data. All signals in a bus use the same extrapolation setting. If any signal in a bus uses enum data, then you cannot use the Linear extrapolation option.

Hold first value

Uses the first data value in the file

Ground value

Uses a value that depends on the data type of MAT-file 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

Dependencies

To generate code that builds ERT or GRT targets or uses SIL or PIL simulation modes, you must set this parameter to Linear extrapolation. For more information on C/C++ code generation with the From File block, see Code Generation.

Programmatic Use

Block Parameter: ExtrapolationBeforeFirstDataPoint
Type: character vector
Values: 'Linear extrapolation' | 'Hold first value' | 'Ground value'
Default: 'Linear extrapolation'

The interpolation method that Simulink uses for a simulation time hit between two time stamps in the MAT-file. Choose one of these interpolation methods.

MethodDescription
Linear interpolation

(Default)

The From File block interpolates using the two corresponding MAT-file 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, the From File block:

    • Upcasts the data to double

    • Performs linear interpolation, as described for double data

    • Downcasts the interpolated value to the original data type

Zero order hold

Uses the data from the first of the two samples

Limitations

You cannot use the Linear interpolation option with enumerated (enum) data. All signals in a bus use the same interpolation setting. If any signal in a bus uses enum data, then you cannot use the Linear interpolation option.

Dependencies

To generate code that builds ERT or GRT targets or uses SIL or PIL simulation modes, you must set this parameter to Linear interpolation. For more information on C/C++ code generation with the From File block, see Code Generation.

Programmatic Use

Block Parameter: InterpolationWithinTimeRange
Type: character vector
Values: 'Linear interpolation' | 'Zero order hold'
Default: 'Linear interpolation'

The extrapolation method for a simulation time hit that occurs after the last time stamp in the MAT-file. Choose one of these extrapolation methods.

MethodDescription
Linear extrapolation

(Default)

If the MAT-file contains only one sample, then the From File block outputs the corresponding data value.

If the MAT-file contains more than one sample, then the From File 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 first data value.

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

    • Upcasts the data to double

    • Performs linear extrapolation, as described for double data

    • Downcasts the extrapolated value to the original data type

Hold last value

Uses the last data value in the file

Ground value

Uses a value that depends on the data type of MAT-file 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

Limitations

You cannot use the Linear extrapolation option with enumerated (enum) data. All signals in a bus use the same extrapolation setting. If any signal in a bus uses enum data, then you cannot use the Linear extrapolation option.

Dependencies

To generate code that builds ERT or GRT targets or uses SIL or PIL simulation modes, you must set this parameter to Linear extrapolation. For more information on C/C++ code generation with the From File block, see Code Generation.

Programmatic Use

Block Parameter: ExtrapolationAfterLastDataPoint
Type: character vector
Values: 'Linear extrapolation' | 'Hold last value' | 'Ground value'
Default: 'Linear extrapolation'

Enables 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 a discontinuity in time stamps, without resorting to excessively small time steps. “Zero-crossing” represents a discontinuity.

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

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

If the input array contains duplicate time stamps (more than one entry with the same time stamp), Simulink detects a zero crossing at those time stamps. 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 nonduplicate time stamps, zero-crossing detection depends on the settings of these parameters:

  • Data extrapolation before first data point

  • Data interpolation within time range

  • Data extrapolation after last data point

The From File block determination of when zero-crossing occurs depends on the time stamp.

Time StampSetting

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 apply:

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

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

This figure illustrates zero-crossing detection for data accessed by a From File block that has these 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

This figure is another illustration of zero-crossing detection for data accessed by a From File 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

Dependencies

To generate code that builds ERT or GRT targets or uses SIL or PIL simulation modes, clear this check box. For more information on C/C++ code generation with the From File block, see Code Generation.

Programmatic Use

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

Block Characteristics

Data Types

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

Direct Feedthrough

no

Multidimensional Signals

yes

Variable-Size Signals

no

Zero-Crossing Detection

yes

[a] Supports up to 32-bit fixed-point data types.

Extended Capabilities

Introduced before R2006a