Click or drag to resize
Accord.NET (logo)

MatReader Class

Reader for .mat files (such as the ones created by Matlab and Octave).
Inheritance Hierarchy
SystemObject
  Accord.IOMatReader

Namespace:  Accord.IO
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.5.0
Syntax
public class MatReader : IDisposable
Request Example View Source

The MatReader type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyBaseStream
Returns the underlying stream.
Public propertyBigEndian
Gets whether the MAT file uses the Big-Endian standard for bit-order. Currently, only little endian is supported.
Public propertyCode exampleDescription
Gets the human readable description of the MAT file.
Public propertyFields
Gets the child nodes contained in this file.
Public propertyItemInt32
Gets a child object contained in this node.
Public propertyItemString
Gets a child object contained in this node.
Public propertyTranspose
Gets whether matrices will be auto-transposed to .NET row and column format if necessary.
Public propertyVersion
Gets the version information about the file. This field should always contain 256.
Top
Methods
  NameDescription
Public methodDispose
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Protected methodDispose(Boolean)
Releases unmanaged and - optionally - managed resources
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Releases unmanaged resources and performs other cleanup operations before the MatReader is reclaimed by garbage collection.
(Overrides ObjectFinalize.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRead(String)
Reads an object from a given key.
Public methodReadT(String)
Reads an object from a given key.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by Matrix.)
Top
Remarks

MAT files are binary files containing variables and structures from mathematical processing programs, such as MATLAB or Octave. In MATLAB, .mat files can be created using its save and load functions. For the moment, this reader supports only version 5 MAT files (Matlab 5 MAT-file).

The MATLAB file format is documented at http://www.mathworks.com/help/pdf_doc/matlab/matfile_format.pdf

Examples
// Create a new MAT file reader
var reader = new MatReader(file);

// Extract some basic information about the file:
string description = reader.Description; // "MATLAB 5.0 MAT-file, Platform: PCWIN"
int    version     = reader.Version;     // 256
bool   bigEndian   = reader.BigEndian;   // false


// Enumerate the fields in the file
foreach (var field in reader.Fields)
  Console.WriteLine(field.Key); // "structure"

// We have the single following field
var structure = reader["structure"];

// Enumerate the fields in the structure
foreach (var field in structure.Fields)
  Console.WriteLine(field.Key); // "a", "string"

// Check the type for the field "a"
var aType = structure["a"].Type; // byte[,]

// Retrieve the field "a" from the file
var a = structure["a"].GetValue<byte[,]>();

// We can also do directly if we know the type in advance
var s = reader["structure"]["string"].GetValue<string>();
See Also