[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: load sparse matrix from matlab hdf5 file
From: |
Martin Helm |
Subject: |
Re: load sparse matrix from matlab hdf5 file |
Date: |
Fri, 01 Apr 2011 00:07:28 +0200 |
Am Donnerstag, den 31.03.2011, 18:41 +0200 schrieb Christian Fischer:
> Hi
>
> I want to load a sparse matrix from hdf5 file created by matlab.
> I ended up with a struct like:
>
> octave3.3.54:3> a
> a =
> {
> data =
>
> 1 2 3
>
> ir =
>
> 0 1 2
>
> jc =
>
> 0 1 2 3
>
> }
>
> Is it possible to load the matrix as sparse matrix? Or is there a quick way to
> convert the struct into a sparse matrix in octave.
>
> Thank you for your help
> Christian
>
This is most probably compressed column storage with zero based indexes,
but to be sure can you post the output from a bit more complex matrix to
identify it really.
In matlab create sparse(magic(4)) export that and show the output after
export to hdf5 and input into octave.
I do not have matlab so I cannot check it myself.
Assuming it is ccs something like that should do:
n = length(a.jc)-1;
ii = repelems(1:n, [1:n; diff(a.jc)]);
mat = sparse(a.ir+1, ii, a.data);
mat should now contain the correct sparse matrix, but please check that
with some tests.