External Interfaces Previous page   Next Page

Reading and Writing MAT-Files

The save command in MATLAB saves the MATLAB arrays currently in memory to a binary disk file called a MAT-file. The term MAT-file is used because these files have the extension .mat. The load command performs the reverse operation. It reads the MATLAB arrays from a MAT-file on disk back into MATLAB workspace.

A MAT-file may contain one or more of any of the data types supported in MATLAB 5 or later, including strings, matrices, multidimensional arrays, structures, and cell arrays. MATLAB writes the data sequentially onto disk as a continuous byte stream.

MAT-File Interface Library

The MAT-file interface library contains a set of routines for reading and writing MAT-files. You can call these routines from within your own C and Fortran programs. We recommend that you use these routines, rather than attempt to write your own code, to perform these operations. By using the routines in this library, you will be insulated from future changes to the MAT-file structure.

The MAT-file library contains routines for reading and writing MAT-files. They all begin with the three-letter prefix mat. These tables list all the available MAT-functions and their purposes.

Table 1-1: C MAT-File Routines  
MAT-Function
Purpose
matOpen
Open a MAT-file
matClose
Close a MAT-file
matGetDir
Get a list of MATLAB arrays from a MAT-file
matGetFp
Get an ANSI C file pointer to a MAT-file
matGetVariable
Read a MATLAB array from a MAT-file
matPutVariable
Write a MATLAB array to a MAT-file
matGetNextVariable
Read the next MATLAB array from a MAT-file
matDeleteVariable
Remove a MATLAB array from a MAT-file
matPutVariableAsGlobal
Put a MATLAB array into a MAT-file such that the load command will place it into the global workspace
matGetVariableInfo
Load a MATLAB array header from a MAT-file (no data)
matGetNextVariableInfo
Load the next MATLAB array header from a MAT-file (no data)

Table 1-2: Fortran MAT-File Routines  
MAT-Function
Purpose
matOpen
Open a MAT-file
matClose
Close a MAT-file
matGetDir
Get a list of MATLAB arrays from a MAT-file
matGetVariable
Get a named MATLAB array from a MAT-file
matGetVariableInfo
Get header for named MATLAB array from a MAT-file
matPutVariable
Put a MATLAB array into a MAT-file
matPutVariableAsGlobal
Put a MATLAB array into a MAT-file
matGetNextVariable
Get the next sequential MATLAB array from a MAT-file
matGetNextVariableInfo
Get header for next sequential MATLAB array from a MAT-file
matDeleteVariable
Remove a MATLAB array from a MAT-file


Previous page  Exchanging Data Files Between Platforms Writing Character Data Next page

© 1994-2005 The MathWorks, Inc.