# Documentation

### This is machine translation

Translated by
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. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

# spalloc

Allocate space for sparse matrix

## Syntax

```S = spalloc(m,n,nz) ```

## Description

`S = spalloc(m,n,nz)` creates an all zero sparse matrix `S` of size `m`-by-`n` with room to hold `nz` nonzeros, where ```nz >= 1```. The matrix can then be generated column by column without requiring repeated storage allocation as the number of nonzeros grows.

`spalloc(m,n,nz)` is shorthand for

`sparse([],[],[],m,n,nz)`

## Examples

To generate efficiently a sparse matrix that has an average of at most three nonzero elements per column

```S = spalloc(n,n,3*n); for j = 1:n S(:,j) = [zeros(n-3,1)' round(rand(3,1))']'; end ```

## See Also

#### Introduced before R2006a

Was this topic helpful?

#### The Manager's Guide to Solving the Big Data Conundrum

Download white paper