External Interfaces/API    

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's 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 6-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
matGetArray
Read a MATLAB array from a MAT-file
matPutArray
Write a MATLAB array to a MAT-file
matGetNextArray
Read the next MATLAB array from a MAT-file
matDeleteArray
Remove a MATLAB array from a MAT-file
matPutArrayAsGlobal
Put a MATLAB array into a MAT-file such that the load command will place it into the global workspace
matGetArrayHeader
Load a MATLAB array header from a MAT-file (no data)
matGetNextArrayHeader
Load the next MATLAB array header from a MAT-file (no data)

Table 6-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
matGetMatrix
Get a named MATLAB array from a MAT-file
matPutMatrix
Put a MATLAB array into a MAT-file
matGetNextMatrix
Get the next sequential MATLAB array from a MAT-file
matDeleteMatrix
Remove a MATLAB array from a MAT-file
matGetString
Read a MATLAB string from a MAT-file
matPutString
Write a MATLAB string to a MAT-file


 Exchanging Data Files Between Platforms Finding Associated Files