Welcome to pymatreader
Introduction
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:
Matlab |
Python |
---|---|
Primitive types (double, single, int, string) |
Primitive numpy types (double, single, int, string) |
Structure |
dict |
Matrix/Vector |
numpy ndarray |
Cell array |
list |
Struct array |
dict containing lists |
Install
pymatreader is available via pypi:
pip install pymatreader
You can also install it via conda:
conda install -c obob pymatreader
Reference
pymatreader only has one function:
- pymatreader.read_mat(filename, variable_names=None, ignore_fields=None, uint16_codec=None)[source]
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.
- Parameters:
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 too small”.
uint16_codec
allows 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.
- Returns:
A structure of nested dictionaries, with variable names as keys and variable data as values.
- Return type:
dict
In case of problems
Please raise an issue here: https://gitlab.com/obob/pymatreader/issues
If you want to contribute
Your contribution is always welcome!
pymatreader is developed on gitlab: https://gitlab.com/obob/pymatreader
Please make sure to include proper tests and adhere to the PEP 8 Style Guide.