random number generator of normal distribution in 2D

조회 수: 1 (최근 30일)
Camilla Colombo
Camilla Colombo 2011년 5월 27일
Hi, does some of you know if is availiable in Matlab a function that generates random numbers from the 2D normal distribution with mean parameter mu and standard deviation parameter sigma provided in the two dimensions? And also the function to get the Gaussian curve corresponding. Something equivalent to: x = normrnd(mean,sigma,npoint); y = gaussmf(x,[sigma mean]); but in 2D.
Many thanks
Camilla

답변 (2개)

Bjorn Gustavsson
Bjorn Gustavsson 2011년 5월 27일
Maybe something like this for the 2-D random points scattered around r0 with a 2-D normal distribution with major and minor widths of sigma1 and 2 rotated phi radians.
r(1,:) = sigma1*randn([nx*ny,1]); r(2,:) = sigma2*randn([nx*ny,1]);
rotM = [cos(phi) -sin(phi);sin(phi) cos(phi)]; r = rotM*r; r0 = [x0,y0];
r(1,:) = r(1,:) + r0(1); r(2,:) = r(2,:) + r0(2);
HTH, Bjoern

Tom Lane
Tom Lane 2011년 5월 29일
Camilla, if you have normrnd then you must have the Statistics Toolbox. In that case check out the mvnrnd function for random number generation, and mvnpdf for the density function.
-- Tom

Community Treasure Hunt

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

Start Hunting!

Translated by