MATLAB Programming

MATLAB Programming MATLAB Programming

cda.psych.uiuc.edu
from cda.psych.uiuc.edu More from this publisher
23.06.2015 Views

6 Data Import and Export Loading Binary Data MAT-files are double-precision binary MATLAB format files created by the save function and readable by the load function. They can be created on one machine and later read by MATLAB on another machine with a different floating-point format, retaining as much accuracy and range as the different formats allow. They can also be manipulated by other programs, external to MATLAB. MAT-filescancontaindatainanuncompressedoracompressedform,orboth. MATLAB knows which variables in the file have been compressed by looking at a tag that it attaches to each variable during the save operation. When loading data from a MAT-file into the workspace, MATLAB automatically handles the decompression of the appropriate data. The External Interface libraries contain C- and Fortran-callable routines to read and write MAT-files from external programs. Loading ASCII Data ASCII files must be organized as a rectangular table of numbers, with each number in a row separated by a blank, comma, or tab character, and with an equal number of elements in each row. MATLAB generates an error if the number of values differs between any two rows. ASCII files can contain MATLAB comments (lines that begin with %). MATLAB returns all the data in the file as a single two-dimensional array of type double. The number of rows in the array is equal to the number of lines in the file, and the number of columns is equal to the number of values on a line. In the workspace, MATLAB assigns the array to a variable named after the file being loaded (minus any file extension). For example, the command load mydata.dat reads all of the data from mydata.dat into the MATLAB workspace as a single array, and assigns it to a variable called mydata. Innamingthevariable,load precedes any leading underscores or digits in filename with an X and replaces any other nonalphabetic characters with underscores. 6-32

Saving and Loading MAT-Files For example, the command load 10-May-data.dat assigns the data in file 10-May-data.dat to a new workspace variable called X10_May_data. 6-33

Saving and Loading MAT-Files<br />

For example, the command<br />

load 10-May-data.dat<br />

assigns the data in file 10-May-data.dat to a new workspace variable called<br />

X10_May_data.<br />

6-33

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!