AW: cannot read/write sparse matrices to matlab v4

Daniel Heiserer danielheiserer at yahoo.com
Wed Jul 9 08:07:47 CDT 2008


Hi,

I "reverse" engineered it. The format is fairyl simple:

matlab v4 Sparse matrix format:

The matlab v4 format for sparse matrices is as follows:
- The T-flag "sparse" (=2) is set in the M0PT header. (0 stands for real
  matrices. 1 for text)
- The matrix is stored with its indices as a full Nx3 (real) or Nx4 (complex) matrix:
The columns have the following meanings:
1st column: row indices
2nd column: column indices
3rd column: real values
(4th column: imaginary values)
remarks:
- the indices are stored as 8byte doubles.
- a last entry is given to indicate the size of the sparse matrix:
nrow,ncol,0. for real or nrow,ncol,0.,0. for sparse matrices
N the number of rows of the storage scheme is NNZ+1.
Where NNZ is the amount of nonzero entries and the 1 stands for the
last zero entry indicating the size of the sparse matrix.


I attach some small examples.

Best regards, daniel heiserer







----- Ursprüngliche Mail ----
Von: David Bateman <David.Bateman at motorola.com>
An: Daniel Heiserer <danielheiserer at yahoo.com>
CC: bug-octave at octave.org
Gesendet: Dienstag, den 8. Juli 2008, 10:29:58 Uhr
Betreff: Re: cannot read/write sparse matrices to matlab v4

Daniel Heiserer wrote:
> Hi,
>
> the read and write of sparse matrices to v4 matlab does not work:
>
> octave:5> tic;load C4.mat;toc
> error: load: can't read sparse matrices
>
>
> When writing is tried, it seems octave will internally create a full matrix before writing it to the v4 file. This will explode once the matrix is too large:
>
>
> N=1E7;C=sparse(ceil(N*rand(N,1)),ceil(N*rand(N,1)),rand(N,1),N,N);
> save -v4 C4.mat C
>
>
> octave version was:
>
> octave:5> version
> ans = 3.0.0
>
>
>  
Huh, I never even realized that matlab could save a sparse matrix to a
v4 file format! The documentation has a flag for the sparse file format
but then doesn't document how the nnz, cidx, ridx and data parts of the
Sparse matrix are stored. So I presumed that as documented they were
saved as full matrices in v4 format. Without knowledge of the v4 sparse
format I'm not really sure how to implement this..

D.

-- 
David Bateman                                David.Bateman at motorola.com
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary


      __________________________________________________________
Gesendet von Yahoo! Mail.
Dem pfiffigeren Posteingang.
http://de.overview.mail.yahoo.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: matlabv4-sparse-matrix.txt.gz
Type: application/x-gzip
Size: 1756 bytes
Desc: not available
Url : https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080709/047ff20d/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ABC4.mat.gz
Type: application/x-gzip
Size: 154 bytes
Desc: not available
Url : https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080709/047ff20d/attachment-0001.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ABD4.mat.gz
Type: application/x-gzip
Size: 240 bytes
Desc: not available
Url : https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080709/047ff20d/attachment-0002.bin 


More information about the Bug-octave mailing list