Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uniformly distributed points in 2D

Tags:

matlab

uniform

How I can generate uniformly distributed points in two dimensions? I tested this code, but I do not want this because in this code x and y are uniform, but the pairs of (x,y) are not uniform.

X=rand(2,N);
x= X(1,:);
y=X(2,:);
figure;                                     
plot(x,y,'.');                              
like image 462
Simin Soleymanpour Avatar asked Dec 06 '25 19:12

Simin Soleymanpour


1 Answers

Your code does uniformly sample the 2D space. But there is also the unifrnd method in Matlab, that samples n-D space.

N = 5000;
rng(320);
X=rand(2,N);
x=X(1,:);
y=X(2,:);
figure('Position',[125 125 1200 500]);                                     
subplot(1,2,1)
plot(x,y,'.');  

rng(320);
X2 = unifrnd(0,1,2,N);
x=X(1,:);
y=X(2,:);
subplot(1,2,2)
plot(x,y,'.');  

Comparison of methods

like image 163
Franz Hahn Avatar answered Dec 09 '25 17:12

Franz Hahn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!