To load signal data into a model using a From File block:
Create a MAT-file with the signal data that you want to load. See Create Data for a From File Block.
Add a From File block to a model. Connect the From File block to the block that the From File provides input to.
Double-click the From File block and specify:
The path to the file that you want to load data from
The data format for the From File block output
How the data is loaded, including sample time, how data for missing data points is handled, and whether to use zero-crossing detection
For a Version 7.0 and earlier MAT-file, the From File block loads the complete, uncompressed data from the file into memory at the start of simulation. For a Version 7.3 MAT-file, the From File block incrementally loads data from the file during simulation.
For each simulation time hit for which the MAT-file contains no matching timestamp, Simulink® uses interpolation or extrapolation to obtain the needed data. You specify the interpolation and extrapolation methods.
During simulation, the From File block cannot load data from a MAT-file that a To File block is exporting data to.
The From File block Sample time parameter specifies the sample time to load data from a MAT-file. The timestamps in the file must be monotonically nondecreasing. For details, see the From File block documentation.
If a simulation time hit does not have a corresponding MAT-file timestamp, then the From File block output depends on:
Whether the simulation time hit occurs before the first timestamp, within the range of timestamps, or after the last timestamp
The interpolation or extrapolation methods that you select
The data type of the MAT-file data
For details about interpolation and extrapolation options, see the documentation for these From File block parameters:
Data extrapolation before first data point
Data interpolation within time range
Data extrapolation after last data point
Sometimes the MAT-file includes duplicate timestamps (two or more data values that have the same timestamp). In such cases, the From File block action depends on when the simulation time hit occurs, relative to the duplicate timestamps in the MAT-file.
Suppose that the MAT-file contains the following data, with three data values having a
timestamp value of
time stamps: 0 1 2 2 2 3 4 data values: 2 3 6 4 9 1 5
The following table describes the From File block output.
|Simulation Time, Relative to Duplicate Timestamp Values in MAT-File||From File Block Action|
|Before the duplicate timestamps|
Uses the first of the duplicate timestamp values as the basis for
interpolation. (In this example, that timestamp value is
|At or after the duplicate timestamps|
Uses the last of the duplicate timestamp values as the basis for
interpolation. (In this example, that timestamp value is
Zero-crossing detection locates a discontinuity in timestamps, without resorting to excessively small time steps. By default, the From File block does not enable zero-crossing detection.
For the From File block, zero-crossing detection occurs only at timestamps in the file. Simulink examines only the timestamps, not the data values.
For bus signals, Simulink detects zero-crossings across all leaf bus elements.
For more information, see the From File block documentation of the Enable zero-crossing detection parameter.
Do not include NaN values in a MAT-file that you load into a From File block.
The From File block loads data that was written by a To File block without any modifications to the data or any other special provisions.
The supported MAT-file versions are:
Version 7.0 or earlier
For a Version 7.0 and earlier MAT-file, the From File block loads the complete, uncompressed data from the file into memory when the simulation begins. For a Version 7.3 MAT-file, the From File block incrementally loads data from the file during simulation.
For more information about MAT-files, see MAT-File Versions (MATLAB).
Convert Version 7.0 and Earlier Version MAT-Files. If you have a Version 7.0 or earlier version MAT-file that you want to use with the
From File block, consider converting the file to Version 7.3. Use a
Version 7.3 MAT-file if you want the From File block to load data
incrementally during simulation or you want to use MATLAB®
timeseries data. For example, to convert a Version 7.0 file named
my_data_file.mat that contains the variable
at the MATLAB command prompt, enter:
load('my_data_file.mat') save('my_data_file.mat', 'var', '-v7.3')
When the From File block loads data from a MAT-file, that data must be
stored in array format or as a MATLAB
Array Data. You can use the array format only for vector, double, noncomplex signal data.
For a Version 7.0 MAT-file, the From File block loads array data, but
The array format for stored data is a matrix containing two or more rows. The matrix in the MAT-file must have the following form:
The first element of each column contains a timestamp. The remainder of each column
contains data for the corresponding output values. Each element must be a double.
Elements cannot include a
MATLAB Timeseries Data. To use bus data with a From File block, use the MATLAB
timeseries format data can have:
Any dimensionality and complexity
Any built-in data type, including
A fixed-point data type with a word length of up to 32 bits
An enumerated data type
For data stored using the array format, the width of the From File output depends on the number of rows in the matrix. For a matrix containing m rows, the block outputs a vector of length m–1.
timeseries format supports the following simulation and code
Model reference accelerator
See the From File block documentation for an example of creating a
MAT-file with MATLAB
timeseries data load with a From Workspace
The timestamps in the file must be monotonically nondecreasing.
The From File block supports loading nonvirtual bus signals.
The data must be in a MATLAB structure that matches the bus hierarchy. Each leaf of the structure must be
The structure can underspecify the bus signal, but must not overspecify the bus signal. The structure cannot have any elements that do not have corresponding signals in the bus.
The structure does not require a
timeseries object for every
element in the bus hierarchy. However, the structure must have a
timeseries object for at least one of the signals in the bus. For
signals that do not specify data, the From File block outputs the ground
If a MAT-file contains only one variable, then the From File block uses that variable. If the MAT-file contains more than one variable:
For Version 7.3 MAT-files, the From File block uses the variable that is first alphabetically.
For Version 7.0 or earlier MAT-files, the From File block uses the first variable. However, for these versions, the ordering algorithm for variables is complicated. Use a MAT-file that contains only the variable with the data that you want the From File block to load.