Skip to main content

The package provides the mat4py module with the functions loadmat and savemat that allows for reading resp. writing data in the Matlab (TM) MAT-file format.

Matlab data is loaded into basic Python data types. Matrices are stored row-major using lists of lists. Matlab structs and cells are represented using Python dicts.

The package can be run from the command line, in which case, it provides a routine for converting Matlab MAT-files to/from JSON files.

Load data from MAT-file

The function loadmat loads all variables stored in the MAT-file into a simple Python data structure, using only Python’s dict and list objects. Numeric and cell arrays are converted to row-ordered nested lists. Arrays are squeezed to eliminate arrays with only one element. The resulting data structure is composed of simple types that are compatible with the JSON format.

Example: Load a MAT-file into a Python data structure:

data = loadmat('datafile.mat')

The variable data is a dict with the variables and values contained in the MAT-file.

Save Python data structure to a MAT-file

Python data can be saved to a MAT-file, with the function savemat. Data has to be structured in the same way as for loadmat, i.e. it should be composed of simple data types, like dict, list, str, int and float.

Example: Save a Python data structure to a MAT-file:

savemat('datafile.mat', data)

The parameter data shall be a dict with the variables.

Command line usage

The package can be run from the command line, in which case, it provides a routine for converting Matlab MAT-files to/from JSON files.

Call:

python -m mat4py.cmd -h

to get help with command line usage.

Known limitations

The following Matlab data structures/types are not supported:

  • Arrays with more than 2 dimensions

  • Arrays with complex numbers

  • Sparse arrays

  • Function arrays

  • Object classes

  • Anonymous function classes

License

The MIT License (MIT) Copyright (c) 2011-2023 Nephics AB

See the LICENSE.txt file.

Release files for mat4py 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mat4py 0.6.0
File Size Uploaded
mat4py-0.6.0.tar.gz 14.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mat4py 0.6.0
File Interpreter ABI Platform
mat4py-0.6.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 28.0 kB

Release files / mat4py-0.6.0.tar.gz

Download URL mat4py-0.6.0.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
438927e6c16831a337596f593eb0b391c4cf6c982280b635ae412e80dff7fd07
BLAKE2b-256 checksum
How to use checksums
9bccf918875b4612d665bf3cba68714014ee599d0131851f99f7d0686f50b800
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / mat4py-0.6.0-py2.py3-none-any.whl

Download URL mat4py-0.6.0-py2.py3-none-any.whl
Size 13.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1c15f39c7df092f01506044f65999fc9c7d71306f8fc850b1003e15ed64c6bae
BLAKE2b-256 checksum
How to use checksums
55e94e2deb2c904e1d0bde3fa49c054160c2f56ffee5d327dc65fe41bb360613
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.1

1 release file

0.2.0

2 release files

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page