Documentation

### This is machine translation

Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

# full

Convert sparse matrix to full storage

## Syntax

``A = full(S)``

## Description

example

````A = full(S)` converts sparse matrix `S` to full storage organization, such that `issparse(A)` returns logical `0` (`false`).```

## Examples

collapse all

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 = (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 = full(S)`
```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\cdot 8=512$ bytes.

• `S` uses storage for 15 nonzero elements, as well as 24 integers describing their positions, for a total of $39\cdot 8=312$ bytes.

`whos`
``` Name Size Bytes Class Attributes A 8x8 512 double S 8x8 312 double sparse ```

## Input Arguments

collapse all

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 an `m`-by-`n` matrix with `nz` nonzero elements, then `full(X)` requires space to store `m*n` elements. On the other hand, `sparse(X)` requires space to store `nz` 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.

Download ebook