From File
Purpose
Read time stamps and signal values from a file.
Library
System
Description
While a simulation is running, the From File block reads time stamps and signal values from a file. The file format can be either a text file with comma separated values (csv) or a MATLAB data file (mat).
During the simulation, the signal values for the current simulation time are read from the file and made available as a vectorized signal at the output of the From File block.
Data layout
The required input data layout differs for these two file types.
- CSV file
A CSV file must contain one or more rows. The first element in each row contains a timestamp; the remaining elements contain data for the corresponding output values. Thus, the total number of columns must be equal to the parameter Number of outputs plus \(1\). The first row may contain column headers instead of numeric values. In this case, it is silently ignored.
- MAT file
A MAT file must contain one matrix with real double values. Compared to the CSV file, the matrix layout is transposed. The total number of rows must be equal to the number of outputs plus \(1\). The first element in each column contains a timestamp, and the remaining elements in each column contain data for the corresponding output values.
Parameters
- Filename
The name or path of the data file to read from. Relative paths are interpreted relative to the model directory.
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 beMyFile.csvorMyFile.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 variableindexwith a value of2, the file name will beMyFile2.csvorMyFile2.mat.- File type
The file format the specified data file has to comply to. The block can read text files with comma separated values (csv) or MATLAB data files (mat).
- Number of outputs
The number of signal values in each data record (row) of the file (which is the number of columns minus one). If this number does not correspond to the actual number of signal values provided by the file, an error message is shown.
- Output before first time stamp
The method used to determine the output of the From File block for simulation times before the first time stamp in the data file. Possible values are
linear extrapolation,hold first valueandspecify value. If the parameter is set tospecify value, an additional parameter field Initial output value is shown to define the output value before the first time stamp.- Initial output value
The output value before the first signal value specified in the data file. This parameter is only visible if Output before first time stamp is set to
specify value. The value can be given as a scalar or a vector. If it is a scalar, it is used for all signals, if it is a vector, its size has to match the Number of outputs parameter.- Output within time range
The method used to determine the output of the From File block for simulation times between time stamps specified in the data file. Possible values are
linear interpolationandzero order hold.- Output after last time stamp
The method used to determine the output of the From File block for simulation times after the last time stamp in the data file. Possible values are
linear extrapolation,hold last valueandspecify value. If the parameter is set tospecify value, an additional parameter field Final output value is shown to define the output value after the last time stamp.- Final output value
The output value after the last signal value specified in the data file. This parameter is only visible if Output after first time stamp is set to
specify value. The value can be given as a scalar or a vector. If it is a scalar, it is used for all signals, if it is a vector, its size has to match the Number of outputs parameter.- Locate discontinuities
Possible values are
onandoff. If this parameter is set toon, the solver will ensure a time step at each time stamp specified in the data file. This setting requires a variable step solver.