The content of this document may be incorrect or outdated.
Print this article Edit this article
Reading variables from a text file in Matlab
The command:
load
by itself, loads all the variables saved in the file matlab.mat. If the file that contains the variable data is named differently than matlab.mat, use the command:
load fname
which will retrieve the variables from the binary file fname.mat.
To read in variable data from a text file (ascii) use the command:
load fname.xyz
which reads the file fname.xyz. This file can be an ASCII file with of numeric data, arranged in m lines with n variables in each line.
Example:
If the file sample.dat contains four lines of numeric text
1.1 1.2 1.3
2.1 2.2 2.3
3.1 3.2 3.3
4.1 4.2 4.3
The command load sample.dat would produce a 4-by-3 matrix named sample in the workspace.
Last Modified:
Dec 19, 2016 11:12 am US/Eastern
Created:
Mar 20, 2007 4:57 pm GMT-4
by
admin
JumpURL: