Programming |
Importing Numeric Data with Text Headers
To import an ASCII data file that contains text headers, use the textscan
function, specifying the headerlines
parameter. textscan
accepts a set of predefined parameters that control various aspects of the conversion. (For a complete list of these parameters, see the textscan
reference page.) Using the headerlines
parameter, you can specify the number of lines at the head of the file that textscan
should ignore.
For example, the file grades.dat
contains formatted numeric data with a one-line text header:
To import this data, first open the file and then use this textscan
command to read the contents:
fid = fopen('grades.dat', 'r'); grades = textscan(fid, '%f %f %f', 3, 'headerlines', 1); grades{:} ans = 78.8000 99.5000 89.5000 ans = 55.9000 66.8000 77.0000 ans = 45.9000 78.0000 56.7000 fclose(fid);
Importing Delimited ASCII Data Files | Importing Mixed Alphabetic and Numeric Data |
© 1994-2005 The MathWorks, Inc.