io.matlab.mio

Module for reading and writing matlab (TM) .mat files

Module Contents

Functions

_open_file(file_like,appendmat) Open file_like and return as file-like object. First, check if object is
mat_reader_factory(file_name,appendmat=True,**kwargs) Create reader for matlab .mat format files.
loadmat(file_name,mdict=None,appendmat=True,**kwargs) Load MATLAB file.
savemat(file_name,mdict,appendmat=True,format=”5”,long_field_names=False,do_compression=False,oned_as=”row”) Save a dictionary of names and arrays into a MATLAB-style .mat file.
whosmat(file_name,appendmat=True,**kwargs) List variables inside a MATLAB file.
_open_file(file_like, appendmat)

Open file_like and return as file-like object. First, check if object is already file-like; if so, return it as-is. Otherwise, try to pass it to open(). If that fails, and file_like is a string, and appendmat is true, append ‘.mat’ and try again.

mat_reader_factory(file_name, appendmat=True, **kwargs)

Create reader for matlab .mat format files.

%(file_arg)s %(append_arg)s %(load_args)s %(struct_arg)s

matreader : MatFileReader object
Initialized instance of MatFileReader class matching the mat file type detected in filename.
file_opened : bool
Whether the file was opened by this routine.
loadmat(file_name, mdict=None, appendmat=True, **kwargs)

Load MATLAB file.

file_name : str
Name of the mat file (do not need .mat extension if appendmat==True). Can also pass open file-like object.
mdict : dict, optional
Dictionary in which to insert matfile variables.
appendmat : bool, optional
True to append the .mat extension to the end of the given filename, if not already present.
byte_order : str or None, optional
None by default, implying byte order guessed from mat file. Otherwise can be one of (‘native’, ‘=’, ‘little’, ‘<’, ‘BIG’, ‘>’).
mat_dtype : bool, optional
If True, return arrays in same dtype as would be loaded into MATLAB (instead of the dtype with which they are saved).
squeeze_me : bool, optional
Whether to squeeze unit matrix dimensions or not.
chars_as_strings : bool, optional
Whether to convert char arrays to string arrays.
matlab_compatible : bool, optional
Returns matrices as would be loaded by MATLAB (implies squeeze_me=False, chars_as_strings=False, mat_dtype=True, struct_as_record=True).
struct_as_record : bool, optional
Whether to load MATLAB structs as numpy record arrays, or as old-style numpy arrays with dtype=object. Setting this flag to False replicates the behavior of scipy version 0.7.x (returning numpy object arrays). The default setting is True, because it allows easier round-trip load and save of MATLAB files.
verify_compressed_data_integrity : bool, optional
Whether the length of compressed sequences in the MATLAB file should be checked, to ensure that they are not longer than we expect. It is advisable to enable this (the default) because overlong compressed sequences in MATLAB files generally indicate that the files have experienced some sort of corruption.
variable_names : None or sequence
If None (the default) - read all variables in file. Otherwise variable_names should be a sequence of strings, giving names of the matlab variables to read from the file. The reader will skip any variable with a name not in this sequence, possibly saving some read processing.
mat_dict : dict
dictionary with variable names as keys, and loaded matrices as values.

v4 (Level 1.0), v6 and v7 to 7.2 matfiles are supported.

You will need an HDF5 python library to read matlab 7.3 format mat files. Because scipy does not supply one, we do not implement the HDF5 / 7.3 interface here.

savemat(file_name, mdict, appendmat=True, format="5", long_field_names=False, do_compression=False, oned_as="row")

Save a dictionary of names and arrays into a MATLAB-style .mat file.

This saves the array objects in the given dictionary to a MATLAB- style .mat file.

file_name : str or file-like object
Name of the .mat file (.mat extension not needed if appendmat == True). Can also pass open file_like object.
mdict : dict
Dictionary from which to save matfile variables.
appendmat : bool, optional
True (the default) to append the .mat extension to the end of the given filename, if not already present.
format : {‘5’, ‘4’}, string, optional
‘5’ (the default) for MATLAB 5 and up (to 7.2), ‘4’ for MATLAB 4 .mat files.
long_field_names : bool, optional
False (the default) - maximum field name length in a structure is 31 characters which is the documented maximum length. True - maximum field name length in a structure is 63 characters which works for MATLAB 7.6+.
do_compression : bool, optional
Whether or not to compress matrices on write. Default is False.
oned_as : {‘row’, ‘column’}, optional
If ‘column’, write 1-D numpy arrays as column vectors. If ‘row’, write 1-D numpy arrays as row vectors.

mio4.MatFile4Writer mio5.MatFile5Writer

whosmat(file_name, appendmat=True, **kwargs)

List variables inside a MATLAB file.

%(file_arg)s %(append_arg)s %(load_args)s %(struct_arg)s

variables : list of tuples
A list of tuples, where each tuple holds the matrix name (a string), its shape (tuple of ints), and its data class (a string). Possible data classes are: int8, uint8, int16, uint16, int32, uint32, int64, uint64, single, double, cell, struct, object, char, sparse, function, opaque, logical, unknown.

v4 (Level 1.0), v6 and v7 to 7.2 matfiles are supported.

You will need an HDF5 python library to read matlab 7.3 format mat files. Because scipy does not supply one, we do not implement the HDF5 / 7.3 interface here.

New in version 0.12.0.