문제

Can anyone help me how to write a MATLAB code to generate 100,000 random samples (1D)?

The samples should follow 2 PDFs:

  1. N(+1, 0.5)
  2. N(-1, 0.5)

where the notation N(µ,σ) indicates a Normal distribution with mean µ and standard deviation σ.

올바른 솔루션이 없습니다

다른 팁

Use the randn() function and substitute in mean and standard deviation as follows

mu + stdev.*randn(100,1)

For more information, check out the matlab help for randn()

http://www.mathworks.com/help/matlab/ref/randn.html

Alternatively, you can use MATLAB's Probability Distribution Objects which make working with probability distributions very easy.

Note this solution requires the Statistics and Machine Learning Toolbox to use makedist() and random().

% MATLAB R2018b
% Define probability distribution objects
pd1 = makedist('Normal',1,0.5');
pd2 = makedist('Normal',-1,0.5');
% Generate Samples
X1 = random(pd1,100,1);
X2 = random(pd2,100,1);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top