| Contents | Index |
S = load(filename)
S = load(filename, variables)
S = load(filename,
'-mat', variables)
S = load(filename,
'-ascii')
load(filename, ...)
load filename ...
S = load(filename) loads the variables from a MAT-file into a structure array, or data from an ASCII file into a double-precision array.
S = load(filename, variables) loads the specified variables from a MAT-file.
S = load(filename, '-mat', variables) forces load to treat the file as a MAT-file, regardless of the extension. Specifying variables is optional.
S = load(filename, '-ascii') forces load to treat the file as an ASCII file, regardless of the extension.
load(filename, ...) loads without combining MAT-file variables into a structure array.
load filename ... is the command form of the syntax, for convenient loading from the command line. With command syntax, you do not need to enclose input strings in single quotation marks. Separate inputs with spaces instead of commas. Do not use command syntax if inputs such as filename are variables. For more information, see Command vs. Function Syntax in the MATLAB Programming Fundamentals documentation.
filename |
Name of a file. If you do not specify filename, the load function searches for a file named matlab.mat. filename can include a file extension and a full or partial path. If filename has no extension (that is, no text after a period), load looks for a file named filename.mat. If filename has an extension other than .mat, the load function treats the file as ASCII data. Default: 'matlab.mat' | ||||
variables |
List of variables to load from the file. Valid for MAT-files only. Use one of the following forms:
Default: all variables in file | ||||
'-mat' |
Keyword that indicates that the specified file is a MAT-file, regardless of the extension. | ||||
'-ascii' |
Keyword that indicates that the specified file is an ASCII file, regardless of the extension. The following remarks apply to loading all ASCII files, even when you do not include the -ascii keyword, but load a file with an extension other than .mat:
|
Load all variables from the demo MAT-file gong.mat. Check the contents of the workspace before and after the load operation.
disp('Contents of workspace before loading file:')
whos
disp('Contents of gong.mat:')
whos -file gong.mat
load gong.mat
disp('Contents of workspace after loading file:')
whosLoad only the variable y from the demo file handel.mat. If the workspace already contains a variable y, the load operation overwrites it with data from the file.
load('handel.mat', 'y')
Create a list of variables to load using a cell array. Call load using function syntax.
%This demo file contains variables X, caption, and map.
demoFile = 'durer.mat';
% Load selected variables.
vars = {'X', 'caption'};
load(demoFile, vars{:});Use regular expressions to load four variables from the demo file accidents.mat that do not begin with 'hwy':
load('accidents.mat', '-regexp', '^(?!hwy)...');
Load the first three variables from accidents.mat, determined alphabetically by variable name:
vars = whos('-file', 'accidents.mat');
load('accidents.mat', vars(1:3).name);Create an ASCII file from several 4-column matrices, and load the data back into a double array named mydata:
a = magic(4); b = ones(2, 4) * -5.7; c = [8 6 4 2]; save -ascii mydata.dat a b c clear a b c load mydata.dat
The easiest way to import data is to use the Import Wizard, a graphical user interface. The Import Wizard imports both MAT-files and ASCII files, and provides direct control over the variables to create. To start the Wizard, select File > Import Data or call uiimport.
clear | importdata | matfile | regexp | save | uiimport | whos
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |