npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mat-for-js

v1.1.0

Published

Converts Matlab Level 5 MAT-files to JavaSript objects

Downloads

92

Readme

mat4js

JavaScript library to load Matlab Level 5 MAT-files as JavaScript objects. Based on the documentation: https://www.mathworks.com/help/pdf_doc/matlab/matfile_format.pdf released for 2019b

Installation

via npm

$ npm install mat4js

then use as

import { read as readmat } from "mat-for-js"
readmat(ArrayBuffer)
import * from "mat-for-js"
mat4js.read(ArrayBuffer)

via script tag

Download dist/mat4js.read.min.js to your webserver and include it in your HTML:

<script type="text/javascript" src="./mat4js.read.min.js"></script>

Read

Use mat4js.read(ArrayBuffer).

It returns a JavaScript object with a .header and .data property.

.header

contains 116 bytes of text.

Padding characters are not truncated.

.data

is an object containing the named arrays in the file. ({name: content})

Matlab stores vectors as 2D but flat arrays (1xn or nx1). These are converted to plain 1D arrays ([1, 2, 3] instead of [[1, 2, 3]]) or strings in case of character arrays. In multidimensional character arrays the characters are not concatenated to form strings, but are kept separate. ({char_array: [["a", "b", "c"], ["d", "e", "f"]]} instead of {char_array: ["abc", "def"]})

Numeric arrays with Int64 or Uint64 data types are converted into an array of BigInt.

Numeric arrays with imaginary component are converted into an array of objects with .r and .i properties for the real and imaginary components respectively.

Scalar structs are converted into objects as would be expected, while non-scalar structs are more akin to cell arrays. For a struct constructed with

S = struct()
S.cell = {1 2; 3 4}
S.fruit = 'apple'

In JavaScript

S.cell[1][0] == 3
S.fruit == "apple"

But for one constructed with S = struct('cell', {1 2; 3 4}, 'fruit', 'apple') (non-scalar):

S[1][0].cell == 3
S[1][1].cell == 4
S[1][0].fruit == "apple"
S[1][1].fruit == "apple"

and S.fruit == "apple" is not accessible.

Sparse arrays are converted to objects with .x and .y properties describing the width and height of the array respectively, and an .nz property containing an array of objects representing non-zero values. These objects also have .x and .y properties for their indices in the matrix and an additional .v for the non-zero value at the index.

Build

If you want to rebuild dist/readmat.min.js, first install the dev dependencies with npm install. Once webpack is installed, run npm run build.

Limitaions

There is no support for Object array types. 64-bit integer type support depends on using a version of JavaScript that includes the DataView.getBigInt64()/DataView.getBigUint64() methods.

Matlab v7.3 MAT-files use HDF5 data structure and are not supported. Reading such files will throw a FeatureError with the .feature property set to "HDF5". There are other JavaScript projects to view HDF5 files: https://github.com/usnistgov/jsfive

There is no write functionality.