jBinary types for reading Matlab mat file with Javascript
Use the MAT typeset defined in this package as you would any jbinary typeset.
This package includes extensive tests showing expected behavior.
Only mat file Level 5 is currently supported.
var jBinary = require('jbinary')
var MAT = require('jMatFile')
jBinary.load('myMat.mat', MAT).then(function (binary) {
var mat = binary.readAll
// or equivalently
var mat = binary.read('mat')
// ... do stuff with mat
})This typeset is designed for use with JS engines that fully utilize typed arrays. Typed arrays provide enormous speed benefits compared to a naive array-based implementation because no new objects are created or pushed; memory is accessed directly as an array.
As a result, this typeset only works with JS engines that fully support typed arrays. As of this writing, this restriction knowingly excludes:
phantomjsbecause it does not supportFloat64Arraynodejsbecause of jdataview's special treatment of node Buffers
The returned Javascript object describing the mat file has the following key properties. The description here does not exhaustively define the format, but hits the most important elements for everyday use.
header- contains info from the mat file header, such as descriptive text, endianness, and version.variables- array of objects describing each matlab variable.
Each variable element has the following properties:
namedescribing the variable's name when it was saved.- Fields
sizefor array of dimension lengths,numelfor total number of elements, andemptyflag for whether the number of elements is 0.sizealways has at least 2 elements. value, a 2D (or higher) array, with each dimension matching the values insize. The elements of the array depend on the type of variable.- Flags
complex,logical,sparse,struct,object,global,cell, each eithertrueorfalse, indicating information about the data in the variable. - If the
valuecan be represented as a 1D iterable array (with possibly zero elements), the fieldvectorwill be present as a 1D array of elements. - If the
valuecan be represented as a scalar, the fieldscalarwill be present and contain the equivalent scalar value. Empty matrices are not scalars. - If the
valuecan be represented as a string, thestringfield will be present and contain the equivalent String object. - If the
valueis an object of a non-primitive class, theclassfield will be present and contain the class name in string form.
- For real numeric types, each element is a Number. For complex types, the
complexflag is set totrueand each element is an object with fieldsreandimfor real and imaginary part, respectively. - For logical types, the
logicalflag is set to true, and each element is a Boolean. - For
stringtypes, each element ofvalueis a string of a single character. - For
structtypes, each element is an object with fields matching the fields of thestruct. The field names can be retrieved withObject.getOwnPropertyNames. The value of each field is avariablewith its ownsize, flags,value, etc. - For
objecttypes, each element is the same as withstruct. - For
celltypes, each element is avariablewith its ownsize, flags,value, etc.