Home > Common Problem > body text

How to generate random numbers in matlab

angryTom
Release: 2020-09-05 16:14:55
Original
68510 people have browsed it

Matlab is a commonly used software for us. Friends who do random processes or probability often use some random numbers. But how are these data generated? The following introduces some common random numbers in matlab.

How to generate random numbers in matlab

Methods that matlab can use to generate random numbers:

1. Uniform distribution:

■ unifrnd (a, b, m, n)

Generate m*n order [a, b] uniform distribution

■ unifrnd (a,b )

Generate a uniform random number [a,b]

Recommended study "Introduction to Programming"

Example:

How to generate random numbers in matlab

2. rand (m, n);

produces m*n order [0, 1] uniformly Distributed random number matrix

■ rand(n);

Generate n*n order [0,1] uniformly distributed random numbers

Example:

How to generate random numbers in matlab

##3、binornd(n,p,[M,N,P,...])

The generated numbers are random numbers that obey the binomial distribution. The parameters of the binomial distribution are: n and p.

Consider a target shooting example. Each shot The hit rate is p, and a total of N guns are fired, then the total number of hits obeys the binomial distribution with parameters (N, p). Note that p must be less than or equal to 1 and non-negative, and N must be an integer.

■ binornd(n,p,[M,N,P,...])

The generated random numbers obey the binomial distribution with parameters (N, p) , these random numbers are arranged into an M*N*P... order matrix. If only M is written, an M*M matrix will be generated;


Example:

How to generate random numbers in matlab

4, unidrnd(N, m,n)

Generate an m*n order discrete uniformly distributed random number matrix; generate an mm*nn matrix with a value between 1-N

Example:

How to generate random numbers in matlab

5, exprnd (mu ,m, n)

Produces m*n order expected value A random number matrix of exponential distribution for mu

Example:

How to generate random numbers in matlab

There are also some other random numbers, which will not be introduced here. The methods are other This is similar to

For more related programming tutorials, please pay attention to

PHP Chinese website!

The above is the detailed content of How to generate random numbers in matlab. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template