Simulink Reference    
From File

Read data from a file

Library

Sources

Description


The From File block outputs data read from a file. The block icon displays the pathname of the file supplying the data.

The file must contain a matrix of two or more rows. The first row must contain monotonically increasing time points. Other rows contain data points that correspond to the time point in that column. The matrix is expected to have this form.

The width of the output depends on the number of rows in the file. The block uses the time data to determine its output, but does not output the time values. This means that in a matrix containing m rows, the block outputs a vector of length m-1, consisting of data from all but the first row of the appropriate column.

If an output value is needed at a time that falls between two values in the 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 file, Simulink extrapolates, using the first two or last two 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 column encountered. For example, for a matrix that has this data:

At time 2, the output is 4, the data point for the first column encountered at that time value.

Simulink reads the file into memory at the start of the simulation. As a result, you cannot read data from the same file named in a To File block in the same model.

Using Data Saved by a To File or a To Workspace Block

The From File block can read data written by a To File block without any modifications. To read data written by a To Workspace block and saved to a file:

Data Type Support

A From File block outputs real signals of type double.

Parameters and Dialog Box

File name
The fully qualified pathname or file name of the file that contains the data used as input. On UNIX, 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 assumes that the file resides in MATLAB's working directory. (To determine the working directory, enter pwd at the MATLAB command line.) If Simulink cannot find the specified file name in the working directory, it displays an error message.
Sample time
The sample period and offset of the data read from the file. See Specifying Sample Time in the online documentation for more information.

Characteristics

Sample Time
Inherited from driven block
Scalar Expansion
No
Dimensionalized
1-D array only
Zero Crossing
No


  From From Workspace