Programming Previous page   Next Page

Importing Numeric Text Data

If your data file contains only numeric data, you can use many of the MATLAB import functions (listed in Table 6-2), depending on how the data is delimited. If the data is rectangular, that is, each row has the same number of elements, the simplest command to use is the load command. (The load function can also be used to import MAT-files, the MATLAB binary format for saving the workspace.)

For example, the file named my_data.txt contains two rows of numbers delimited by space characters:

When you use load as a command, it imports the data and creates a variable in the workspace with the same name as the filename, minus the file extension:

If you want to name the workspace variable something other than the filename, use the functional form of load. In the following example, the data from my_data.txt is loaded into the workspace variable A:


Previous page  Using Import Functions with Text Data Importing Delimited ASCII Data Files Next page

© 1994-2005 The MathWorks, Inc.