User`s manual

Using MAT-Files
6-3
Using MAT-Files
This section describes the various techniques for importing data to and
exporting data from the MATLAB environment. The main topics that are
discussed are:
“Importing Data to MATLAB”
“Exporting Data from MATLAB”
“Exchanging Data Files Between Platforms”
“Reading and Writing MAT-Files”
“Finding Associated Files”
The most important approach to importing and exporting data involves the use
of MAT-files, the data file format that MATLAB uses for saving data to your
disk. MAT-files provide a convenient mechanism for moving your MATLAB
data between different platforms and for importing and exporting your data to
other stand-alone MATLAB applications.
To simplify your use of MAT-files in applications outside of MATLAB, we have
developed a library of access routines with a
mat prefix that you can use in your
own C or Fortran programs to read and write MAT-files. Programs that access
MAT-files also use the
mx prefixed API routines discussed in Chapter 2,
“Creating C Language MEX-Files” and Chapter 3, “Creating Fortran
MEX-Files.”
Importing Data to MATLAB
You can introduce data from other programs into MATLAB by several
methods. The best method for importing data depends on how much data there
is, whether the data is already in machine-readable form, and what format the
data is in. Here are some choices. Select the one that best meets your needs.
Enter the data as an explicit list of elements.
If you have a small amount of data, less than 10-15 elements, it is easy to
type the data explicitly using brackets [ ]. This method is awkward for larger
amounts of data because you can’t edit your input if you make a mistake.
Create data in an M-file.
Use your text editor to create an M-file that enters your data as an explicit
list of elements. This method is useful when the data isn’t already in