Skip to main content

Load and save data in the Matlab (TM) MAT-file format.

Project description

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-2020 Nephics AB

See the LICENSE.txt file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

mat4py-0.4.3-py2.py3-none-any.whl (13.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file mat4py-0.4.3-py2.py3-none-any.whl.

File metadata

  • Download URL: mat4py-0.4.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/43.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for mat4py-0.4.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7c64282d455a5e0da1901c1f7c56e7e52a62ab6d6c1bf53d933e3d8b5c2b8b44
MD5 c5f0bab5e57360c44601b50f6aebec7e
BLAKE2b-256 c702a6855d4e61f7b6484535c1a2500c207bc0772e9c70ea6a3e30c553a6e3ef

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page