full - Convert sparse matrix to full storage - MATLAB (original) (raw)
Convert sparse matrix to full storage
Syntax
Description
`A` = full([S](#mw%5Fcc01e120-fea8-419b-a679-69edd17e288d))
converts sparse matrix S
to full storage organization, such thatissparse(A)
returns logical 0
(false
).
Examples
Change the storage format of a matrix and compare the storage requirements.
Create a random sparse matrix. The display of sparse matrices in MATLAB® omits all zeros and shows the location and value of nonzero elements.
rng default %for reproducibility S = sprand(8,8,0.3)
S = 8×8 sparse double matrix (15 nonzeros) (2,1) 0.0344 (7,1) 0.4456 (8,1) 0.7547 (2,2) 0.4387 (4,3) 0.7655 (7,3) 0.6463 (8,4) 0.2760 (1,6) 0.9502 (5,6) 0.1869 (8,6) 0.6797 (3,7) 0.3816 (4,7) 0.7952 (8,7) 0.6551 (6,8) 0.4898 (7,8) 0.7094
Convert the matrix to full storage. The MATLAB display of the matrix reflects the new storage format.
A = 8×8
0 0 0 0 0 0.9502 0 0
0.0344 0.4387 0 0 0 0 0 0
0 0 0 0 0 0 0.3816 0
0 0 0.7655 0 0 0 0.7952 0
0 0 0 0 0 0.1869 0 0
0 0 0 0 0 0 0 0.4898
0.4456 0 0.6463 0 0 0 0 0.7094
0.7547 0 0 0.2760 0 0.6797 0.6551 0
Compare the storage requirements of the two formats:
A
uses storage for 64 doubles (8 bytes each), or 64⋅8=512 bytes.S
uses storage for 15 nonzero elements, as well as 24 integers describing their positions, for a total of 39⋅8=312 bytes.Name Size Bytes Class Attributes
A 8x8 512 double
S 8x8 312 double sparse
Input Arguments
Sparse matrix to convert, specified as a matrix. If S
is already a full matrix, then A
is identical to S
.
Tips
- If
X
is anm
-by-n
matrix withnz
nonzero elements, thenfull(X)
requires space to storem*n
elements. On the other hand,sparse(X)
requires space to storenz
elements and(nz+n+1)
integers.
The density of a matrix (nnz(X)/numel(X)
) determines whether it is more efficient to store the matrix as sparse or full. The exact crossover point depends on the matrix class, as well as the platform. For example, in 32-bit MATLAB®, a double sparse matrix with less than about 2/3 density requires less space than the same matrix in full storage. In 64-bit MATLAB, however, double matrices with fewer than half of their elements nonzero are more efficient to store as sparse matrices.
Extended Capabilities
The full
function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced before R2006a