Hi,
the resulting size of the sparse matrix depends from the number of zero entries. Consider this:
A = randi(10,100);
A(A<=7) = 0;
B = sparse(A);
whos A B
Name Size Bytes Class Attributes
A 100x100 80000 double
B 100x100 49096 double sparse
The code above produced a sparse matrix which has about 60% size then the normal one. There should be about 70% zeros in it.
If we only have about 30% zeros the situation changes:
A = randi(10,100);
A(A<=3) = 0;
B = sparse(A);
whos A B
Name Size Bytes Class Attributes
A 100x100 80000 double
B 100x100 113240 double sparse
Now the size of B is about 40% bigger than A.
EDIT - Now the same example using complex numbers:
about 70% zeros:
R = randi(10,100);
I = ones(100);
C = complex(R,I);
C(real(C)<=7) = 0;
D = sparse(C);
whos C D
gives:
Name Size Bytes Class Attributes
C 100x100 160000 double complex
D 100x100 71944 double sparse, complex
and the same with about 30% zeros:
R = randi(10,100);
I = ones(100);
C = complex(R,I);
C(real(C)<=3) = 0;
D = sparse(C);
whos C D
gives:
Name Size Bytes Class Attributes
C 100x100 160000 double complex
D 100x100 168928 double sparse, complex
The values differ, but the fundamental effect is the same.
Best regards
Stephan
Best Answer