Programming |
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:
load my_data.txt; whos Name Size Bytes Class my_data 2x5 80 double array my_data my_data = 1 2 3 4 5 6 7 8 9 10
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
:
Using Import Functions with Text Data | Importing Delimited ASCII Data Files |
© 1994-2005 The MathWorks, Inc.