Documentation

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.

randerr

Generate bit error patterns

Syntax

out = randerr(m)
out = randerr(m,n)
out = randerr(m,n,errors)
out = randerr(m,n,errors,seed)
out = randerr(m,n,errors,streamhandle)

Description

For all syntaxes, randerr treats each row of out independently.

out = randerr(m) generates an m-by-m binary matrix, where each row has exactly one nonzero entry in a random position. Each allowable configuration has an equal probability.

out = randerr(m,n) generates an m-by-n binary matrix, where each row has exactly one nonzero entry in a random position. Each allowable configuration has an equal probability.

out = randerr(m,n,errors) uses the errors input to determine the number of nonzero entries in each row of the output m-by-n binary matrix.

  • If errors is a scalar, it is the number of nonzero entries in each row.

  • If errors is a row vector, it lists the possible number of nonzero entries in each row.

  • If errors is a matrix having two rows, the first row lists the possible number of nonzero entries in each row and the second row lists the probabilities that correspond to the possible error counts. The elements in the second row of errors must sum to one.

Once randerr determines the number of nonzero entries in a given row, each configuration of that number of nonzero entries has equal probability.

out = randerr(m,n,errors,seed) accepts a seed value for initializing the uniform random number generator rand.

out = randerr(m,n,errors,streamhandle) accepts a random stream handle to generate uniform random noise samples by using rand. Providing a random stream handle or using the reset function on the default random stream object enables you to generate repeatable noise samples. If you want to generate repeatable noise samples, then either reset the random stream input before calling randerr or use the same seed input. For more information, see RandStream.

Examples

collapse all

Generate an 8-by-7 binary matrix in which each row is equally likely to have either zero or two nonzero elements.

out = randerr(8,7,[0 2])
out = 

     0     1     0     0     0     1     0
     0     1     0     0     0     1     0
     0     0     0     0     0     0     0
     0     0     0     0     0     1     1
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     1     0     0     0     1
     0     0     1     0     1     0     0

Now generate a matrix in which it is three times more likely that a row will have two nonzero elements.

out = randerr(8,7,[0 2; 0.25 0.75])
out = 

     0     0     0     0     1     0     1
     0     1     0     0     0     0     1
     0     0     1     0     0     1     0
     0     1     0     0     1     0     0
     1     0     0     0     1     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0

See Also

Functions

System Objects

Introduced before R2006a

Was this topic helpful?