Wolfram Language & System 11.0 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)

MTX (.mtx)

  • Import and Export fully support the Matrix Market file format.


    Matrix Market matrix format.
    Used for exchanging and storing test matrices.
    Plain text format.
    File format of the NIST Matrix Market collection of standard test matrices.
    Stores numerical or pattern matrices in a dense ("array format") or sparse ("coordinate format") representation.
    Developed in 1996 by R. Boisvert, R. Pozo, K. Remington, and J. Dongarra.
    Maintained by the US National Institute of Standards and Technology (NIST).

Import and ExportImport and Export

  • Import["file.mtx"] imports matrix data from a Matrix Market file.
  • Export["file.mtx",expr] exports any numerical or pattern matrix to a Matrix Market file.
  • Import["file.mtx"] reads an MTX matrix file and returns an array.
  • The Wolfram Language converts "array format" files to packed arrays and "coordinate format" files to sparse arrays.
  • Import["file.mtx",elem] imports the specified element from a Matrix Market file.
  • Import["file.mtx",{elem,suba,subb,}] imports a subelement.
  • Import["file.mtx",{{elem1,elem2,}}] imports multiple elements.
  • The import format can be specified with Import["file","MTX"] or Import["file",{"MTX",elem,}].
  • Export["file.mtx",expr,elem] creates a Matrix Market file by treating expr as specifying element elem.
  • Export["file.mtx",{expr1,expr2,},{{elem1,elem2,}}] treats each expri as specifying the corresponding elemi.
  • Export["file.mtx",expr,opt1->val1,] exports expr with the specified option elements taken to have the specified values.
  • Export["file.mtx",{elem1->expr1,elem2->expr2,},"Rules"] uses rules to specify the elements to be exported.
  • See the reference pages for full general information on Import and Export.
  • ImportString and ExportString support the Matrix Market file format.


  • General Import elements:
  • "Elements"list of elements and options available in this file
    "Rules"full list of rules for each element and option
    "Options"list of rules for options, properties, and settings
  • Data representation elements:
  • "Data"matrix data given as a packed or sparse array
    "Graphics"a visual representation of the values of the matrix elements
  • Import uses the "Data" element by default.
  • Import["file.mtx","Graphics"] uses MatrixPlot to render the matrix structure as graphics.
  • Meta-information elements:
  • "Comments"user comments stored in the file
    "MatrixStructure"symmetry properties of the matrix
  • Possible values for "MatrixStructure" are:
  • "Hermitian"matrix that is equal to its own conjugate transpose
    "General"matrix without transposition symmetry
    "SkewSymmetric"matrix whose transpose is also its negative
    "Symmetric"matrix that is equal to its transpose

ExamplesExamplesopen allclose all

Basic Examples  (2)Basic Examples  (2)

This imports a sparse matrix from an MTX sample file, giving a visual representation of it:

Click for copyable input

Import this file as a sparse array object:

Click for copyable input

This exports a 2×2 matrix to MTX:

Click for copyable input
Click for copyable input
Introduced in 2007