load
Load variables from file into workspace
Syntax
Description
load( loads data from
filename)filename into the MATLAB® workspace. If filename is a MAT-file, then
load(filename) loads variables from the file; if
filename is an ASCII file, then load(filename)
loads a double-precision array containing data from the file.
Note
Security Considerations: The
load command might execute code contained in a MAT-file as it
initializes variables. Avoid calling load on untrusted
MAT-files.
load( treats
filename,"-mat")filename as a MAT-file, regardless of the file extension.
loads data into
S = load(___)S, using any of the input argument combinations in previous
syntaxes. If filename is a MAT-file, then S is a
structure array; if filename is an ASCII file, then
S is an
m-by-n double-precision array
containing data from the file, where m is the number of lines
in the file and n is the number of values on each line.
load is the command form of the
syntax. Command form requires fewer special characters. You do not need to type
parentheses or enclose the input in single or double quotes. Separate inputs with spaces
instead of commas. If any input includes spaces, enclose it in single quotes.filename
For example, to load a file named test.mat, these statements are
equivalent:
load test.mat % command form
load("test.mat") % function form
You can include any of the inputs described in previous syntaxes. For example, to load
the variable X from a file named my
file.mat:
load 'my file.mat' X % command form, using single quotes
load("my file.mat","X") % function form, using double quotes
Do not use command form when any of the inputs, such as filename,
are variables.
Examples
Input Arguments
Limitations
When working with remote data,
loaddoes not support treating the input file as an ASCII file.
Tips
You can use these strategies to speed up loading of MAT-files from network drives:
Use the
copyfilefunction to copy the file from the network drive to a local drive before applying theloadfunction to the local copy.Use the
matfilefunction to access the file without loading it into the workspace.Decrease or disable refreshing of the Files panel. To do this, go to the Home tab, and in the Environment section, select Settings. Select MATLAB > Current Folder. You can either increase the Number of seconds between auto-refresh value to a number greater than the default value of 3, or clear the Auto-refresh view from file system check box to disable the feature.
Algorithms
If you do not specify an output when loading from an ASCII file, the
load function creates a variable named after the loaded file (minus any
file extension). For example, the command load mydata.dat reads data into a
variable named mydata. For example, see Load ASCII File
To create the variable name, load precedes any leading underscores or
digits in filename with an X and replaces any other
nonalphabetic characters with underscores. For example, the command load
10-May-data.dat creates a variable named X10_May_data.