Reading External Data
One uses the load command to read in external data that is in a tabular format. The load routine
returns a matrix that contains the data. Matlab comments (prefaced with a % sign) can be included in the data.
load filename | Extracts the values from the file with name 'filename.mat'. The data is placed in a variable with the name filename. |
load filename.ext | Extracts the values from the file with name 'filename.ext'. The data is placed in a variable with the name filename. |
load testdata.dat testdata testdata = 3 3 4 4 5 7
# Given a file testdata2.dat with the entries
% x y
3.0 2.0
4.0 3.0
5.0 4.0
% read the data, then print and plot the data
load testdata2.dat testdata2 testdata2 = 3 2 4 3 5 4 plot(testdata2(:,1), testdata2(:,2))
UCLA Mathematics Department | ©2000 |