Main Content

From File

Load data from MAT-file

  • Library:
  • Simulink / Sources

  • From File block

Description

TheFrom Fileblock 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®timeseriesformat.

TheFrom Fileblock icon shows the name of the MAT-file that supplies the data to the block.

You can have multipleFrom Fileblocks that load from the same MAT-file.

The supported MAT-file versions are Version 7.0 or earlier and Version 7.3. TheFrom Fileblock 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, seeLoad 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 MATLABtimeseriesformat. When you loadtimeseriesdata using theFrom Fileblock, the data type of the time data must bedouble.

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 isuntitled.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 enterpwd.)

After you specify theFile name, you can use the view button () to preview the signal from the MAT-file. For more information, seePreview 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 theFrom Fileblock, seeCode Generation.

Programmatic Use

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

The data type for the data that theFrom Fileblock outputs. For nonbus types, you can useInherit: autoto skip any data type verification. If you specify an output data type, then theFrom Fileblock verifies that the data in the file matches the specified data type. For more information, seeControl Signal Data Types.

If you setOutput data typeas a bus object, the bus object must be available when you compile the model. For each signal in bus data, theFrom Fileblock verifies that data type, dimensions, and complexity are the same for the data and for the bus object.

Click theShow data type assistantbuttonto display theData Type Assistant, which helps you set the data type attributes. For more information, seeSpecify 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: ' | 'Bus: ' | ''
Default:'Inherit: auto'

Specify the sample period and offset.

TheFrom Fileblock loads data from a MAT-file, using a sample time that either:

  • You specify for theFrom Fileblock.

  • TheFrom Fileblock inherits from the blocks into which theFrom Fileblock feeds data.

The default sample time is0, which specifies a continuous sample time. The MAT-file is loaded at the base (fastest) rate of the model. For details, seeSpecify 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.

Method Description
Linear extrapolation

(Default)

If the MAT-file contains only one sample, then theFrom Fileblock outputs the corresponding data value.

If the MAT-file contains more than one sample, then theFrom Fileblock linearly extrapolates using the first two samples:

  • Fordoubledata, linearly extrapolates the value using the first two samples

  • ForBooleandata, outputs the first data value

  • For a built-in data type other thandoubleorBoolean,From Fileblock:

    • Upcasts the data todouble

    • Performs linear extrapolation (as described fordoubledata)

    • Downcasts the extrapolated data value to the original data type

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

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:

  • -使用地面val定点数据类型ue

  • Numeric types other than fixed point —Uses0

  • Boolean— Usesfalse

  • 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 toLinear extrapolation. For more information on C/C++ code generation with theFrom Fileblock, seeCode 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.

Method Description
Linear interpolation

(Default)

TheFrom Fileblock interpolates using the two corresponding MAT-file samples:

  • Fordoubledata, linearly interpolates the value using the two corresponding samples

  • ForBooleandata, usesfalsefor the first half of the sample andtruefor the second half.

  • For a built-in data type other thandoubleorBoolean,From Fileblock:

    • Upcasts the data todouble

    • Performs linear interpolation, as described fordoubledata

    • 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 theLinear interpolationoption with enumerated (enum) data. All signals in a bus use the same interpolation setting. If any signal in a bus usesenumdata, then you cannot use theLinear interpolationoption.

Dependencies

To generate code that builds ERT or GRT targets or uses SIL or PIL simulation modes, you must set this parameter toLinear interpolation. For more information on C/C++ code generation with theFrom Fileblock, seeCode 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.

Method Description
Linear extrapolation

(Default)

If the MAT-file contains only one sample, then theFrom Fileblock outputs the corresponding data value.

If the MAT-file contains more than one sample, then theFrom Fileblock linearly extrapolates using data values of the last two samples:

  • Fordoubledata, extrapolates the value using the last two samples.

  • ForBooleandata, outputs the first data value.

  • For built-in data types other than double orBoolean:

    • Upcasts the data todouble

    • Performs linear extrapolation, as described fordoubledata

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

  • -使用地面val定点数据类型ue

  • Numeric types other than fixed point —Uses0

  • Boolean— Usesfalse

  • Enumerated data types — Uses default value

Limitations

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

Dependencies

To generate code that builds ERT or GRT targets or uses SIL or PIL simulation modes, you must set this parameter toLinear extrapolation. For more information on C/C++ code generation with theFrom Fileblock, seeCode Generation.

Programmatic Use

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

Enables zero-crossing detection.

TheZero-Crossing Detectionparameter applies only if theSample timeparameter is set to0(continuous).

金宝app仿真软件使用技术,即零交点detection to locate a discontinuity in time stamps, without resorting to excessively small time steps. “Zero-crossing” represents a discontinuity.

For theFrom Fileblock, 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

TheFrom Fileblock determination of when zero-crossing occurs depends on the time stamp.

Time Stamp Setting

First

Data extrapolation before first data pointis set toGround value.

Between first and last

Data interpolation within time rangeis set toZero-order hold.

Last

One or both of these settings apply:

  • Data extrapolation after last data pointis set toGround value.

  • Data interpolation within time rangeis set toZero-order hold.

This figure illustrates zero-crossing detection for data accessed by aFrom Fileblock 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 aFrom Fileblock. 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 theFrom Fileblock, seeCode 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