| Contents | Index |
Sinks
The To File block inputs a signal and writes the signal data to a MAT-file. Use the To File block to log signal data.
The To File block icon shows the name of the output file.
The block writes to the output file incrementally, with minimal memory overhead during simulation. If the output file exists at the time the simulation starts, the block overwrites the file. The file automatically closes when simulation is complete. If simulation terminates abnormally, the To File block saves the data it has logged up until the point of the abnormal termination.
Use the Save format parameter to specify which of the following two formats the To File block uses for writing data:
Timeseries (default)
Array
For the Timeseries format, the To File block:
Writes data in a MATLAB timeseries object
Supports writing multidimensional, real, or complex output values
Supports writing output values that have any built-in data type, including Boolean, enumerated (enum), and fixed-point data with a word length of up to 32 bits
For the Array format, the To File block:
Writes data into a matrix containing two or more rows. The matrix has the following form:

Simulink writes one column to the matrix for each data sample. The first element of the column contains the time stamp. The remainder of the column contains data for the corresponding output values.
Supports writing data that is one-dimensional, double, and noncomplex
The To File block Decimation and Sample Time parameters control when data is written to the file.
The From File block can use data written by a To File block in any format (Timeseries or Array) without any modifications to the data or other special provisions.
The From Workspace block can read data that is in the array format and is the transposition of the data written by the To File block. To provide the required format, use MATLAB commands to load and transpose the data from MAT-file.
When a To File block is in a referenced model, that model must be a single-instance model. Only one instance of such a model can exist in a model hierarchy. See General Reusability Limitations for more information.
To avoid the overhead of compressing data in real time, the To File block writes an uncompressed Version 7.3 MAT-file. To compress the data within the MAT-file, load and save the file in MATLAB. The resaved file is smaller than the original MAT-file that the To File block created, because the Save command compresses the data in the MAT-file.
The To File block accepts real or complex signal data of any data type that Simulink supports, with the exception that the word length for fixed-point data must be 32 bits or less.

The path or file name of the MAT-file in which to store the output. On UNIX systems, the pathname can start with a tilde (~) character signifying your home folder. The default file name is untitled.mat. If you specify a file name without path information, Simulink software stores the file in the MATLAB working folder. (To determine the working folder, type pwd at the MATLAB command line.) If the file already exists, Simulink software overwrites it.
The name of the matrix contained in the named file. The default name is ans.
The data format (timeseries or array) that the To File block uses for writing data. The default format is Timeseries.
The decimation factor, n, where n specifies writing data at every nth time that the block executes. The default decimation is 1, which writes data at every time step.
Specifies the sample period and offset at which to collect points. This parameter is useful when you are using a variable-step solver where the interval between time steps might not be constant. The default is-1, which inherits the sample time from the driving block. See How to Specify the Sample Time for more information.
Sample Time | Specified in the Sample time parameter |
Dimensionalized | Yes |
Importing and Exporting Simulation Data, From File, From Workspace, To Workspace

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