Load data from MAT-file
Simulink / Sources
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.
Port_1
— File dataMAT-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
File name
— Path or file nameuntitled.mat
(default) | path, or MAT-file namePath 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.
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.
Block Parameter:
FileName
|
Type: character vector |
Values: MAT-file name |
Default:
'untitled.mat'
|
Output data type
— Output data typeInherit: auto
(default) | 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: <bus_object>
| <data type expression>
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.
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'
|
Sample time
— Sampling period and offset0
| scalar | vectorSpecify 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.
Block Parameter:
SampleTime
|
Type: character vector |
Values: scalar | vector |
Default:
'0'
|
Data extrapolation before first data point
— Extrapolation method for simulation times before initial time stamp in MAT-fileLinear extrapolation
(default) | Hold first value
| Ground value
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 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:
You cannot use the |
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:
|
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.
Block Parameter:
ExtrapolationBeforeFirstDataPoint
|
Type: character vector |
Values:
'Linear extrapolation' | 'Hold first value' | 'Ground
value'
|
Default:
'Linear extrapolation'
|
Data interpolation within time range
— Interpolation method for simulation times that fall between two time stamps in the MAT-fileLinear interpolation
(default) | Zero order hold
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) The From File block interpolates using the two corresponding MAT-file samples:
|
Zero order hold | Uses the data from the first of the two samples |
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.
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.
Block Parameter:
InterpolationWithinTimeRange
|
Type: character vector |
Values:
'Linear interpolation' | 'Zero order hold'
|
Default:
'Linear interpolation'
|
Data extrapolation after last data point
— Extrapolation method for simulation times after last time stamp in MAT-fileLinear extrapolation
(default) | Hold last value
| Ground value
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 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:
|
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:
|
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.
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.
Block Parameter:
ExtrapolationAfterLastDataPoint
|
Type: character vector |
Values:
'Linear extrapolation' | 'Hold last value' | 'Ground
value'
|
Default:
'Linear extrapolation'
|
Enable zero-crossing detection
— Enable zero-crossing detectionoff
(default) | on
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 Stamp | Setting |
---|---|
First | Data extrapolation before first data
point is set to |
Between first and last | Data interpolation within time
range is set to |
Last | One or both of these settings apply:
|
This figure illustrates zero-crossing detection for data accessed by a From File block that has these settings:
Data extrapolation before first data point
— Linear extrapolation
Data interpolation within time range (for
internal points) — Zero order
hold
Data extrapolation after last data point
— Linear 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
point — Hold first
value
Data interpolation within time range
— Zero order hold
Data extrapolation after last data point
— Hold last value
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.
Block Parameter:
ZeroCross |
Type: character vector |
Values:
'off' | 'on' |
Default:
'on' |
Not recommended for production code.
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.
For a From File block, generating code that builds ERT or GRT targets or uses SIL or PIL simulation modes requires that:
The MAT-file contains a nonempty, finite, real matrix with at least two rows.
Use a data type of double
for the
matrix.
Do not include any NaN, Inf, or -Inf elements in the matrix.
In the From File block parameters dialog box:
Set the Data extrapolation before first data
point and Data extrapolation after
last data point parameters to
Linear extrapolation
.
Set the Data interpolation within time
range parameter to Linear
interpolation
.
Clear the Enable zero-crossing detection parameter.
Supports up to 32-bit fixed-point data types.