MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Q: Problem importing two sparse arrays from a .mat file (Update)

  • To: mathgroup at
  • Subject: [mg107567] Q: Problem importing two sparse arrays from a .mat file (Update)
  • From: Claudius Schnörr <Claudius.Schnoerr at>
  • Date: Wed, 17 Feb 2010 07:03:26 -0500 (EST)


how can two sparse arrays be read from a .mat file?
(My Mma version is 7.0.1 on windows)
(The .mat files are version 5)

An example creating some .mat files in the other system:

A = [ 0, 12, 13; 21, 0, 0; 0, 32, 0];    % a (3x3)-matrix
H = sparse(A);
H2 = sparse(A);
save( 'test_A.mat', 'A' );               % file with a dense matrix
save( 'test_H.mat', 'H' );               % file with a sparse matrix
save( 'test_H2.mat', 'H' );
save( 'test_H2.mat',  '-append', 'H2' ); % with two sparse matrices

Reading them in Mma:

A = Import["test_A.mat", "Data"][[1]];
Head[A]                                  (*a List*)

H = Import["test_H.mat", "Data"][[1]];
Head[H]                                  (*a SparseArray*)

How can multiple sparse arrays be read?
The following doesn't work!

H2 = Import["test_H2.mat", {"Data", {"SparseArray", "SparseArray"}}];

I expected a List of two SparseArrays in H2.
Simply reading by H2=Import["test_H2.mat"] doesn't work either.
Is this a bug or do I use the wrong syntax?

The files can be downloaded here if you can't create the .mat-files 

Any help is welcome.

  • Prev by Date: Re: (any documentation for) linear syntax?
  • Next by Date: Re: Extract parameters from FIndFit output
  • Previous by thread: Re: Arctangent approximation
  • Next by thread: simple BSpline surfaces could not be exported