To File
Purpose
Write time stamps and signal values to a file.
Library
System
Description
While a simulation is running, the To File block writes the time stamps and the values of its input signals to a file. The file format can be either a text file with comma separated values (csv) or a MATLAB data file (mat). CSV files can be imported by all common spreadsheet tools like Microsoft Excel.
In a csv file a new row is appended for each time step. When writing to a MATLAB file the resulting data contains a column for each time step.
The first value for each data record is the simulation time of the current simulation step. The value is followed by the signal values of the input signal.
Parameters
- Filename
- The name of the data file to write to. Files will be stored relative to
the model directory unless an absolute file path is given. The data file will be
created if it doesn't exist. An existing file of the same name will be overwritten.
If you choose the option literal, the string that you enter is taken literally as the basename of the data file. So, if you enter e.g. MyFile, the file name will be MyFile.csv or MyFile.mat.
If you choose the option evaluate, the string that you enter is interpreted as a MATLAB/Octave expression that must yield a string, which in turn is taken as the basename of the data file. So, if you enter e.g. ['MyFile' num2str(index)] and the current workspace contains a variable index with a value of 2, the file name will be MyFile2.csv or MyFile2.mat.
- File type
- The file format to use for the data file. The file can be written as a text file with comma separated values (csv) or as a MATLAB data file (mat).
- Sample time
- For positive values the input data will be written to the data file once in the given simulation interval. If the value is set to 0 the input data is written to the data file in each simulation step. See also the Discrete-Periodic sample time type in section Sample Times.