Giter VIP home page Giter VIP logo

mat4py's Introduction

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

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

See the LICENSE.txt file.

mat4py's People

Contributors

jcbsv avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.