Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

spalloc - Allocate space for sparse matrix

Syntax

S = spalloc(m,n,nzmax)

Description

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

spalloc(m,n,nzmax) is shorthand for

sparse([],[],[],m,n,nzmax)

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
  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS