Welcome to pymatreader¶
pymatreader is a small python package that provides a consistent way of loading all versions of Matlab .mat files.
pymatreader returns a python
dict with all the variables found in the
.mat file. Matlab data types are converted to python datatypes as follows:
|Primitive types (double, single, int, string)||Primitive numpy types (double, single, int, string)|
|Struct array||dict containing lists|
pymatreader is available via pypi:
pip install pymatreader
You can also install it via conda:
conda install -c obob pymatreader
pymatreader only has one function:
read_mat(filename, variable_names=None, ignore_fields=None, uint16_codec=None)¶
This function reads .mat files of version <7.3 or 7.3 and returns the contained data structure as a dictionary of nested substructure similar to scipy.io.loadmat style.
- filename (str) – Path and filename of the .mat file containing the data.
- variable_names (list of strings, optional) – Reads only the data contained in the specified dict key or variable name. Default is None.
- ignore_fields (list of strings, optional) – Ignores every dict key/variable name specified in the list within the entire structure. Only works for .mat files v 7.3. Default is .
- uint16_codec (str | None) – If your file contains non-ascii characters, sometimes reading
it may fail and give rise to error message stating that “buffer is
uint16_codecallows to specify what codec (for example: ‘latin1’ or ‘utf-8’) should be used when reading character arrays and can therefore help you solve this problem.
A structure of nested dictionaries, with variable names as keys and variable data as values.