Monday, November 5, 2007

Correctly creating Octave sparse matrix files

If you are generating sparse matrix files to load into Octave, here is the format:
# name: NAME_OF_MATRIX
# type: sparse matrix
# nnz: NUMBER_OF_NONZERO_ENTRIES
# rows: NUMBER_OF_ROWS
# columns: NUMBER_OF_COLUMNS
1 1 1
2 1 3

Note: Each line is (row, column, value). The entries should first be sorted by column number, then by row.