Skip to Main Content Skip to Search
Product Documentation

To File - Write data to file

Library

Sinks

Description

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.

Specifying the Format for Writing Data

Use the Save format parameter to specify which of the following two formats the To File block uses for writing data:

For the Timeseries format, the To File block:

For the Array format, the To File block:

Controlling When Data is Written to the File

The To File block Decimation and Sample Time parameters control when data is written to the file.

Saving Data for Use by a From File Block

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.

Saving Data for Use by a From Workspace Block

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.

Limitation on To File blocks in a Referenced Model

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.

Compressing MAT-File Data

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.

Data Type Support

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.

Parameters and Dialog Box

File name

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.

Variable name

The name of the matrix contained in the named file. The default name is ans.

Save format

The data format (timeseries or array) that the To File block uses for writing data. The default format is Timeseries.

Decimation

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.

Sample time

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.

Characteristics

Sample Time

Specified in the Sample time parameter

Dimensionalized

Yes

See Also

Importing and Exporting Simulation Data, From File, From Workspace, To Workspace

  


Related Products & Applications

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