필터 지우기
필터 지우기

How to generate random numbers in a Gaussian distribution?

조회 수: 186 (최근 30일)
Ali Almakhmari
Ali Almakhmari 2023년 2월 7일
답변: Swaraj 2023년 2월 8일
Given A = 1 and B = 5, and knowing that the mean is 2.5 and the standard deviation is 1, I want to generate 1000 random points between A and B using a normal (Gaussian) distribution. I am unsure how to do this in MATLAB efficienctly.
  댓글 수: 6
Walter Roberson
Walter Roberson 2023년 2월 7일
values = mean + randn(1000,1) * sigma;
The repmat() is valid, but slower than needed for this purpose.
Ali Almakhmari
Ali Almakhmari 2023년 2월 7일
I see. Thank you all so much!!

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

채택된 답변

Swaraj
Swaraj 2023년 2월 8일
You can use the randn function in MATLAB.
You can follow the following steps:
  1. Generate Random Numbers from a standard normal distribution.
  2. Scale and shift them to match the desired Mean and Standard Deviation.
Please go through the code below:
A = 1;
B = 5;
std = 1;
mean = 2.5;
step1Result = mean + std * randn(1000,1);
step2Result = min(max(step1Result,A),B);

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by