matfile
Access and change variables directly in MAT-files, without loading into memory
Syntax
m = matfile(filename)
m = matfile(filename,'Writable',isWritable)
Description
creates a MAT-file object,m
= matfile(filename
)m
, connected to the MAT-file namedfilename
. The object allows you to access and change variables directly in a MAT-file, without having to load the variables into memory.
The partial loading and saving that thematfile
function provides requires less memory than theload
andsave
commands, which always operate on entire variables.
enables or disables write access to the file.m
= matfile(filename
,'Writable',isWritable
)
Examples
Input Arguments
Output Arguments
Limitations
matfile
does not support linear indexing. You must specify indices for all dimensions.matfile
does not support indexing into:Variables of tables
Cells of cell arrays
Fields of structure arrays
User-defined classes
Sparse arrays
You cannot assign complex values to an indexed portion of a real array.
You cannot evaluate function handles using the
m
output. For example, if your MAT-file contains function handlemyfunc
, the syntaxm.myfunc()
attempts to index into the function handle, and does not invoke the function.Efficient partial loading and saving requires Version 7.3 MAT-files. To create a Version 7.3 MAT-file, call the
save
function with the'-v7.3'
option. For example, to convert an existing MAT-file nameddurer.mat
to Version 7.3, call:load('durer.mat'); save('mycopy_durer.mat','-v7.3');
Tips
Using the
end
keyword as part of an index causes MATLAB to load the entire variable into memory. For very large variables, this load operation results inOut
of
Memory
errors. Rather than usingend
, determine the extent of a variable,myVar
, with thesize
method, such as:sizeMyVar = size(m,'myVar')