Jose Ramon
Jose Ramon

Reputation: 5388

Error using sparse index into matrix is too large

I ve got a huge adjacency matrix in a sparse representation. I ve got 70.000 and 300.000 edges and the structure of adjacency file is a Nx3 matrix with the first two columns to be the connected nodes the the third column to be the weight. I am trying to read from matlab. Firstly I import the file, and secondly I am trying to create the sparse matrix with spconvert:

adj1 = spconvert(gr);

However I am receiving the following error message:

??? Error using ==> sparse
Index into matrix is too large.
Error in ==> spconvert at 53
   S = sparse(D(:,1),D(:,2),D(:,3));

The biggest value of the matrix is 2.537020525000000e+09 and correspond to a node. Any idea what is wrong here?

Upvotes: 1

Views: 340

Answers (1)

Fraukje
Fraukje

Reputation: 683

If you look at the documentation of sparse it tells you that:

Note:   If any value in i or j is larger than 2^31-1 for 32-bit platforms, or 2^48-1 on 64-bit platforms, then the sparse matrix cannot be constructed.

This corresponds to 2.15 e^09 for the maximum biggest value on a 32-bit platform and therefore that is giving you the error message since your biggest value is larger than this. As a solution I propose rescaling your weight values, for instance with log.

Upvotes: 3

Related Questions