Main Content

trnd

Student's t random numbers

Description

example

r = trnd(nu) generates a random number from the Student's t distribution with nu degrees of freedom.

example

r = trnd(nu,sz1,...,szN) generates an array of random numbers from the Student's t distribution, where sz1,...,szN indicates the size of each dimension.

example

r = trnd(nu,sz) generates an array of random numbers from the Student's t distribution, where size vector sz specifies size(r).

Examples

collapse all

Generate a single random number from the Student's t distribution with 10 degrees of freedom.

nu = 10;
r = trnd(nu)
r = 1.0585

Generate a 1-by-6 array of Student's t random numbers with 1 degree of freedom.

nu1 = ones(1,6); % 1-by-6 array of ones
r1 = trnd(nu1)
r1 = 1×6

    0.2108    7.8450  -11.0511    0.4134    4.3293   -0.8323

If you specify nu as a scalar, it expands into a constant array with dimensions specified by sz1,...,szn.

Generate a 2-by-6 array of Student's t random numbers with 3 degrees of freedom.

nu2 = 3;
sz1 = 2;
sz2 = 6;
r2 = trnd(nu2,sz1,sz2)
r2 = 2×6

    0.9257    0.3379    0.6477   -2.2792   -2.8371    0.3632
   -0.2996   -0.6845   -1.2554   -0.5134    1.0458   -0.5521

If you specify both nu and sz as arrays, then the dimensions specified by sz must match the dimension of nu.

Generate a 1-by-6 array of Student's t random numbers with 1 to 6 degrees of freedom.

nu3 = 1:6;
sz = [1 6];
r3 = trnd(nu3,sz)
r3 = 1×6

    1.3609    0.1845   -4.0246   -0.8724   -0.7507    2.3493

Input Arguments

collapse all

Degrees of freedom for the Student's t distribution, specified as a scalar value or an array of scalar values.

To generate random numbers from multiple distributions, specify nu using an array. Each element in r is the random number generated from the distribution specified by the corresponding degrees of freedom in nu.

Example: [9 19 49 99]

Data Types: single | double

Size of each dimension, specified as separate arguments of integers.

If nu is an array, then the specified dimensions sz1,...,szN must match the dimensions of nu. The default values of sz1,...,szN are the dimensions of nu.

  • If you specify a single value sz1, then r is a square matrix of size sz1-by-sz1.

  • If the size of any dimension is 0 or negative, then r is an empty array.

  • Beyond the second dimension, trnd ignores trailing dimensions with a size of 1. For example, trnd(5,3,1,1,1) produces a 3-by-1 vector of random numbers from the distribution with 5 degrees of freedom.

Example: 3,5

Data Types: single | double

Size of each dimension, specified as a row vector of integers.

If nu is an array, then the specified dimensions sz must match the dimensions of nu. The default values of sz are the dimensions of nu.

  • If you specify a single value [sz1], then r is a square matrix of size sz1-by-sz1.

  • If the size of any dimension is 0 or negative, then r is an empty array.

  • Beyond the second dimension, trnd ignores trailing dimensions with a size of 1. For example, trnd(5,[3 1 1 1]) produces a 3-by-1 vector of random numbers from the distribution with 5 degrees of freedom.

Example: [3 5]

Data Types: single | double

Output Arguments

collapse all

Student's t random numbers, returned as a scalar value or an array of scalar values with the dimensions specified by sz1,...,szN or sz. Each element in r is the random number generated from the distribution specified by the corresponding degrees of freedom in nu.

Alternative Functionality

  • trnd is a function specific to the Student's t distribution. Statistics and Machine Learning Toolbox™ also offers the generic function random, which supports various probability distributions. To use random, specify the probability distribution name and its parameters. Note that the distribution-specific function trnd is faster than the generic function random.

  • To generate random numbers interactively, use randtool, a user interface for random number generation.

Extended Capabilities

Version History

Introduced before R2006a