help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Importing a sparse matrix to Octave


From: John W. Eaton
Subject: Importing a sparse matrix to Octave
Date: Fri, 24 Jul 2009 14:29:54 -0400

On 24-Jul-2009, Chong Yidong wrote:

| I have a finite element program (whose source code I can alter) that
| generates a large sparse complex matrix.  I'd like to import this matrix
| into Octave for further manipulation.  One possibility is to save the
| matrix into a .m file and run the script in Octave, but this seems
| rather inefficient.  Can anyone suggest a better way?

The simplest thing would probably be to have your program write out a
file with the following format:

  # name: s
  # type: sparse complex matrix
  # nnz: 70
  # rows: 10
  # columns: 10
  1 1 (0,1.145193428282681)
  2 1 (0,0.5663270399606521)
  3 1 (0,0.007270909230606313)
  4 1 (0,0.1480797228543177)
  5 1 (0,0.2478795113138578)
  ...

The first column is the row index, the second is the column index, and
the third is the corresponding value (real,complex).  The number of
elements must match the value of NNZ.  To load this file into Octave,
use the load command.

If you want to transfer binary values instead, then you could write
out the data in Octave's binary format, or in the Matlab .mat file
format.  Octave's binary format is fairly simple, but only documented
by the code that reads/writes it in the Octave sources.  The .mat file
format is documented by the MathWorks.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]