load

Reads the content of a MAT file.

Syntax

R = load(filename)

R = load(filename, variable)

R = load(filename, type)

load filename

Inputs

filename
Path and name of the MAT file to load.
Type: string
variable
List of the variables to load, separated by a comma.
If no variable is specified, all variables are loaded.
Type: string
type
Used to indicate the file to load is ASCII.
The only valid option is '-ascii'.
Type: string

Outputs

R
Struct with values read from the file.
Type: matrix

Example

Read data from a .mat file using load function:
% create a matrix
M = [ 1923.71288  4023.03575  9768.82832  9195.83701  104.13143  4261.35201   ];
% create a string
st='hello';
% save to file
save('file.mat')
%simple load
load('file.mat')
%load only the matrix M
load('file.mat','M')
% load and return content in a struct
R=load('file.mat')
struct [
M: [Matrix] 1 x 6
1923.71288  4023.03575  9768.82832  9195.83701  104.13143  4261.35201
st: hello
]
Read data from a .csv file using load function:
% foo.dat is an ASCII file with 2 lines and 3 columns (either separated by spaces or commas)
R=load('foo.dat','-ascii')
R = [Matrix] 2 x 3
1923.71288  4023.03575  9768.82832  
9195.83701  104.13143  4261.35201