distributed.spalloc - Allocate space for sparse distributed matrix - MATLAB (original) (raw)

Main Content

Allocate space for sparse distributed matrix

Syntax

SD = distributed.spalloc(M,N,nzmax) SD = distributed.spalloc(___,typename)

Description

SD = distributed.spalloc(M,N,nzmax) creates an M-by-N all-zero sparse distributed matrix with room to hold nzmax nonzeros.

SD = distributed.spalloc(___,typename) also specifies the data type (class) of the sparse distributed matrix. The typename input can be either "single", "double", or"logical". (since R2025a)

Examples

Allocate space for a 1000-by-1000 sparse distributed matrix with room for up to 2000 nonzero elements, then define several elements:

N = 1000; SD = distributed.spalloc(N,N,2*N); for ii=1:N-1 SD(ii,ii:ii+1) = [ii ii]; end

Use spalloc to initialize a 10-by-10 all-zero sparse distributed single-precision matrix with room for up to 20 nonzero elements. Define several elements in the matrix.

SD = distributed.spalloc(10,10,20,"single"); SD(1:3,1:3) = magic(3);

Version History

Introduced in R2009b

expand all

You can specify the output data type by specifying thetypename argument as "double","single", or logical.