matfile

Accesses variables in a MAT-file without loading the whole file.

Category: Data Import and Analysis > Data Import and Export

Syntax

m = matfile(filename)

Creates a read-only object for an existing MAT-file.

m = matfile(filename, 'Writable', true)

Allows writing to the file.

Description

A matfile object behaves like a struct whose fields are read from disk when you use them. That lets you pull a row or a slice out of a large variable without holding the entire array in memory.

Input arguments

filename
MAT-file name.
'Writable'
Set to true to allow changes.

Output arguments

m
Object whose properties are the variables in the file. Indexing such as m.x(2, :) reads part of a variable.

Example

Read part of a variable

x = magic(3); y = 'abc';
save('mf.mat', 'x', 'y');
m = matfile('mf.mat');
m.x(2, :)
m.y
m.Properties.Writable
Output
ans = 1×3

     3     5     7
ans = 'abc'
ans = logical
   0

See also

load save whos fopen