| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink |
| Contents | Index |
| Learn more about Simulink |
Sources
The From File block reads scalar or vector data of type double from a MAT-file outputs the data as a signal. The block's icon shows the pathname of the file supplying the data. Simulink software reads the MAT-file into memory at the start of the simulation, automatically uncompressing it if it had previously been saved by MATLAB in a compressed format. Therefore:
Enough memory must be available at the start of simulation to contain the complete uncompressed MAT-file.
A From File block cannot read data from a MAT-file that is being written by a To File block during the current simulation.
The MAT-file contains the stored data as a matrix of two or more rows. The first element of each column contains a simulation time. The remainder of each column contains scalar or vector data for the time shown at the top of the column, one element for each data point in the input. The time values in the first row must increase monotonically. The matrix in the file has this form:

The width of the output depends on the number of rows in the MAT-file. The block uses the time data at the top of each column to determine when to output the data values in the column, but does not output the time value itself. This means that given a MAT-file containing m rows, the block outputs a vector of length m-1, consisting of data from all but the first row of each column.
See Importing Data from a Workspace for guidelines on choosing time vectors for discrete systems.
If an output value is needed at a time that falls between two values in the MAT-file, the value is linearly interpolated between the appropriate values. If the required time is less than the first time value or greater than the last time value in the MAT-file, Simulink software extrapolates, using the first two or last two data points to compute a value.
If the matrix includes two or more columns at the same time value, the output is the data point for the first such column encountered. For example, for a matrix that has this data:
time values: 0 1 2 2 data points: 2 3 4 5
At time 2, the output is 4, the data point for the first column encountered at that time value.
The From File block can read data written by a To File block without any modifications to the data or other special provisions.
The From File block can read data written by a To Workspace block subject to the following requirements:
The data must include the simulation times. The easiest way to include time data in the simulation output is to specify a variable for time on the Data Import/Export pane of the Configuration Parameters dialog box. See Data Import/Export Pane for more information.
The data must be the transposition of the data saved to the workspace by the To Workspace block. Before saving the data to a MAT-file, transpose it to the form expected by the From File block.
The data in the file must be scalar or vector data of type double.
The From File block can read data only in MAT-file format. The block can output only vector and scalar data of type double. The block cannot output matrix signals or complex data.

The fully qualified pathname or file name of the MAT-file that contains the data used as input. On UNIX® systems, the pathname can start with a tilde (~) character signifying your home directory. The default file name is untitled.mat. If you specify an unqualified file name, Simulink software assumes that the MAT-file resides in the MATLAB working directory. (To determine the working directory, enter pwd at the MATLAB command line.) If Simulink software cannot find the specified file name in the working directory, it displays an error message.
The sample period and offset of the data read from the file. The default is 0, which specifies continuous sample time: the MAT-file is read at the base (fastest) rate of the model. See How to Specify the Sample Time for more information.
If the specified Sample time requires data at a time for which the MAT-file contains no matching time stamp, Simulink software extrapolates or interpolates to obtain the needed data, as described in Missing and Duplicate Time Stamps. If the MAT-file contains columns with time stamps that the specified Sample time never requires, the data points in columns with those time stamps are ignored.
Sample Time | Specified in the Sample time parameter |
Scalar Expansion | No |
Dimensionalized | 1-D array only |
Zero Crossing | No |
Importing and Exporting Data, From Workspace, To File, To Workspace
![]() | From | From Workspace | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |