This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Create codistributed sparse array of uniformly distributed pseudo-random values


CS = codistributed.sprand(m,n,density)
CS = sprand(n,codist)


CS = codistributed.sprand(m,n,density) creates an m-by-n sparse codistributed array with approximately density*m*n uniformly distributed nonzero double entries.

Optional arguments to codistributed.sprand must be specified after the required arguments, and in the following order:

  • codist — A codistributor object specifying the distribution scheme of the resulting array. If omitted, the array is distributed using the default distribution scheme. For information on constructing codistributor objects, see the reference pages for codistributor1d and codistributor2dbc.

  • 'noCommunication' — Specifies that no interworker communication is to be performed when constructing the array, skipping some error checking steps.

CS = sprand(n,codist) is the same as CS = codistributed.sprand(n, codist). You can also use the optional arguments with this syntax. To use the default distribution scheme, specify a codistributor constructor without arguments. For example:

    CS = codistributed.sprand(8,8,0.2,codistributor1d());


With four workers,

    CS = codistributed.sprand(1000,1000,0.001);

creates a 1000-by-1000 sparse codistributed double array CS with approximately 1000 nonzeros. CS is distributed by its second dimension (columns), and each worker contains a 1000-by-250 local piece of CS.

    codist = codistributor1d(2,1:numlabs);
    CS = sprand(10,10,0.1,codist);

creates a 10-by-10 codistributed double array CS with approximately 10 nonzeros. CS is distributed by its columns, and each worker contains a 10-by-labindex local piece of CS.


When you use sprand on the workers in the parallel pool, or in an independent or communicating job (including pmode), each worker sets its random generator seed to a value that depends only on the labindex or task ID. Therefore, the array on each worker is unique for that job. However, if you repeat the job, you get the same random data.

Introduced in R2009b

Was this topic helpful?