Main Content

randerr

Generate bit error patterns

Description

Use the randerr function to generate bit error patterns. For all syntaxes, randerr treats each row of the output independently.

out = randerr(m) generates an m-by-m binary matrix, where each row has exactly one nonzero entry in a random position. Each permutation 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 permutation has an equal probability.

example

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.

example

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

example

out = randerr(m,n,errors,randstream) specifies a random stream object to generate uniform random noise samples by using the rand function. Providing a random stream object or using the reset (RandStream) function on the default random stream object enables you to generate repeatable noise samples.

Note

To generate repeatable noise samples, use the same seed input value for each call of randerr or reset the random stream input before calling randerr. For more information on resetting the random stream, see the RandStream object.

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 = 8×7

     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

Generate a matrix in which each row is three times more likely to have two nonzero elements rather than zero nonzero elements.

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

     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

Demonstrate generation of a random error matrix without a seed input value for a nonrepeatable output and with the seed input value for a repeatable output.

Specify input parameters for the output matrix dimensions, the number of errors, and a seed value.

m = 2;
n = 8;
errors = 2;
seed = 1234;

Use the randerr function to generate a random error binary matrix twice with the same command. The output binary matrix values are the same for each execution of the randerr function.

out = randerr(m,n,errors,seed)
out = 2×8

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

out = randerr(m,n,errors,seed)
out = 2×8

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

Change the seed value and call the randerr function twice. The binary matrix output values are the same for each execution of the randerr function, but they differ from the binary matrix values output using the previous seed value.

seed = 345;
out = randerr(m,n,errors,seed)
out = 2×8

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

out = randerr(m,n,errors,seed)
out = 2×8

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

Use the randerr function to generate a random error binary matrix twice with the same command, not specifying a seed input value. The output matrix values change for each execution of the randerr function.

out = randerr(m,n,errors)
out = 2×8

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

out = randerr(m,n,errors)
out = 2×8

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

Input Arguments

collapse all

Size of the random binary matrix, specified as a positive integer.

  • When you specify only the input m, the random binary matrix output is of size m-by-m.

  • When you specify the inputs m and n, the random binary matrix output is of size m-by-n.

Data Types: double

Column size of the random binary matrix, specified as a positive integer.

Data Types: double

Number of nonzero entries, specified as one of these forms.

  • If specified as a integer, errors defines the number of 1s in each row.

  • If specified as a integer row vector, errors defines the number of 1s possible in each row. Every number of 1s included in this vector occurs with equal probability.

  • If specified as a two-row matrix, the first row of errors defines the integer number of 1s possible in any given row of the output matrix. The second row specifies the probabilities of each corresponding number of ones. The elements in the second row of errors must sum to 1.

Data Types: double

Seed value for initializing the uniform random number generator used in the rand function, specified as nonnegative integer value less than 232.

Data Types: double

Random stream object to generate uniform random noise samples by using the rand function, specified as a RandStream object. Providing a random stream object or using the reset (RandStream) function on the default random stream object enables you to generate repeatable noise samples.

Output Arguments

collapse all

Random binary matrix output, returned as a matrix of binary values.

  • When you specify only the input m, this output is of size m-by-m.

  • When you specify the inputs m and n, this output is of size m-by-n.

Data Types: double

Version History

Introduced before R2006a

See Also

Functions

Objects