How to generate random number from cumulative distribution function (CDF) in Matlab

조회 수: 13 (최근 30일)
Hi everyone,
Similar to R program, I'm looking for a code in Matlab that I can generate a set of random number with a specific mean (M) and standard deviation (sd).
R code to generate random number with normal distribution from CDF:
> pnorm(1.96, mean=0, sd=1)
[1] 0.9750021

채택된 답변

Image Analyst
Image Analyst 2015년 6월 5일
For the more general case of an arbitrary CDF , you have to use inverse transform sampling. Attached is an example for generating a Rayleigh transform.

추가 답변 (2개)

Image Analyst
Image Analyst 2015년 6월 5일
Did you see the example in the help for randn()? Here it is:
Random Numbers from Normal Distribution with Specific Mean and Variance
This example shows how to create an array of
random floating-point numbers that are drawn
from a normal distribution having a mean of 500 and variance of 25.
The randn function returns a sample of random numbers from a normal distribution
with mean 0 and variance 1. The general theory of random variables
states that if x is a random variable whose mean is μ
x
and variance is σ
2
x
, then the random variable, y, defined by y=ax+b,
where a and b are constants, has mean μ
y
=aμ
x
+b and variance σ
2
y
=a
2
σ
2
x
. You can apply this concept to get a sample of
normally distributed random numbers with mean 500 and variance 25.
First, initialize the random number generator to make the results in this example repeatable.
rng(0,'twister');
Create a vector of 1000 random values
drawn from a normal distribution with a mean of 500
and a standard deviation of 5.
a = 5;
b = 500;
y = a.*randn(1000,1) + b;

Sean de Wolski
Sean de Wolski 2015년 6월 5일
doc slicesample
doc random
  댓글 수: 1
Moe
Moe 2015년 6월 5일
with this command:
rnd = slicesample(initial,nsamples,'pdf',pdf)
Can you give me a simple example of it?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by