Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

From File - Read data from MAT-file

Library

Sources

Description

The From File block reads scalar or vector data of type double from a MAT-file outputs the data as a signal. The block's icon shows the pathname of the file supplying the data. Simulink software reads the MAT-file into memory at the start of the simulation, automatically uncompressing it if it had previously been saved by MATLAB in a compressed format. Therefore:

The MAT-file contains the stored data as a matrix of two or more rows. The first element of each column contains a simulation time. The remainder of each column contains scalar or vector data for the time shown at the top of the column, one element for each data point in the input. The time values in the first row must increase monotonically. The matrix in the file has this form:

The width of the output depends on the number of rows in the MAT-file. The block uses the time data at the top of each column to determine when to output the data values in the column, but does not output the time value itself. This means that given a MAT-file containing m rows, the block outputs a vector of length m-1, consisting of data from all but the first row of each column.

See Importing Data from a Workspace for guidelines on choosing time vectors for discrete systems.

Missing and Duplicate Time Stamps

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

time values:    0 1 2 2
data points:    2 3 4 5

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

Using Data Saved by a To File Block

The From File block can read data written by a To File block without any modifications to the data or other special provisions.

Using Data Saved by a To Workspace Block

The From File block can read data written by a To Workspace block subject to the following requirements:

Data Type Support

The From File block can read data only in MAT-file format. The block can output only vector and scalar data of type double. The block cannot output matrix signals or complex data.

Parameters and Dialog Box

File name

The fully qualified pathname or file name of the MAT-file that contains the data used as input. On UNIX® systems, 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 software assumes that the MAT-file resides in the MATLAB working directory. (To determine the working directory, enter pwd at the MATLAB command line.) If Simulink software 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. The default is 0, which specifies continuous sample time: the MAT-file is read at the base (fastest) rate of the model. See How to Specify the Sample Time for more information.

If the specified Sample time requires data at a time for which the MAT-file contains no matching time stamp, Simulink software extrapolates or interpolates to obtain the needed data, as described in Missing and Duplicate Time Stamps. If the MAT-file contains columns with time stamps that the specified Sample time never requires, the data points in columns with those time stamps are ignored.

Characteristics

Sample Time

Specified in the Sample time parameter

Scalar Expansion

No

Dimensionalized

1-D array only

Zero Crossing

No

See Also

Importing and Exporting Data, From Workspace, To File, 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-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS