From File
Load data from MAT-file
- Library:
Simulink / Sources
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®timeseries
format.
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
Port_1
— File data
scalar | vector | matrix | N-D array
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 MATLABtimeseries
format. When you loadtimeseries
data 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
File name
— Path or file name
untitled.mat
(default) | path, or MAT-file name
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' |
Output data type
— Output data type
Inherit: auto
(default) |double
|single
|int8
|uint8
|int16
|uint16
|int32
|uint32
|int64
|uint64
|boolean
|fixdt(1,16,0)
|fixdt(1,16,2^0,0)
|Enum:
|Bus:
|
The data type for the data that theFrom Fileblock outputs. For nonbus types, you can useInherit: auto
to 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: |
Default:'Inherit: auto' |
Sample time
— Sampling period and offset
0
| scalar | vector
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' |
Data extrapolation before first data point
— Extrapolation method for simulation times before initial time stamp in MAT-file
Linear 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 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:
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:
|
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' |
Data interpolation within time range
— Interpolation method for simulation times that fall between two time stamps in the MAT-file
Linear 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) TheFrom Fileblock interpolates using the two corresponding MAT-file samples:
|
Zero order hold |
Uses the data from the first of the two samples |
Limitations
You cannot use theLinear interpolation
option with enumerated (enum
) data. All signals in a bus use the same interpolation setting. If any signal in a bus usesenum
data, then you cannot use theLinear interpolation
option.
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' |
Data extrapolation after last data point
— Extrapolation method for simulation times after last time stamp in MAT-file
Linear 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 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:
|
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:
|
Limitations
You cannot use theLinear extrapolation
option with enumerated (enum
) data. All signals in a bus use the same extrapolation setting. If any signal in a bus usesenum
data, then you cannot use theLinear extrapolation
option.
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' |
Enable zero-crossing detection
— Enable zero-crossing detection
off
(default) |on
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 to |
Between first and last |
Data interpolation within time rangeis set to |
Last |
One or both of these settings apply:
|
This figure illustrates zero-crossing detection for data accessed by aFrom Fileblock 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 aFrom Fileblock. 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
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' |
Model Examples
Block Characteristics
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
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.
从文件块,生成代码的构建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 theData extrapolation before first data pointandData extrapolation after last data pointparameters to
Linear extrapolation
.Set theData interpolation within time rangeparameter to
Linear interpolation
.Clear theEnable zero-crossing detectionparameter.
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
Supports up to 32-bit fixed-point data types.
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)