A = full(S)
A = full(S)
converts the storage of a matrix from sparse to full. If A
is already full, full(A)
returns A
.
Let X
be an m
-by-n
matrix with nz = nnz(X)
nonzero entries. Then full(X)
requires space to store m*n
real numbers while sparse(X)
requires space to store nz
real numbers and (nz+n)
integers. On most computers, a real number requires twice as much storage as an integer. On these computers, sparse(X)
requires less storage than full(X)
if the density, nnz/(m*n)
, is less than one third. Operations on sparse matrices, however, require more execution time per element than those on full matrices, so density is considerably less than two-thirds before sparse storage is used.
sparse(S)
and full(S)
require about the same number of bytes of storage.
S = sparse(rand(200,200) < 2/3);
A = full(S);
whos
Name Size Elements Bytes Density Complex
A 200 by 200 40000 320000 Full No
S 200 by 200 26797 322364 0.6699 No
sparse
(c) Copyright 1994 by The MathWorks, Inc.