二维中均匀分布的点
Uniformly distributed points in 2D
如何生成二维均匀分布的点?
我测试了这段代码,但我不想这样,因为在这段代码中 x
和 y
是统一的,但是 (x,y)
对不统一。
X=rand(2,N);
x= X(1,:);
y=X(2,:);
figure;
plot(x,y,'.');
您的代码确实对 2D space 进行了统一采样。但是Matlab中也有unifrnd
的方法,采样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,'.');
scatterhist()
function is useful for visualizing marginal distributions along with the correlation structure. Image and code below (using @FranzHahn's ).
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,'.');
scatterhist(x,y,'Direction','out')
如何生成二维均匀分布的点?
我测试了这段代码,但我不想这样,因为在这段代码中 x
和 y
是统一的,但是 (x,y)
对不统一。
X=rand(2,N);
x= X(1,:);
y=X(2,:);
figure;
plot(x,y,'.');
您的代码确实对 2D space 进行了统一采样。但是Matlab中也有unifrnd
的方法,采样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,'.');
scatterhist()
function is useful for visualizing marginal distributions along with the correlation structure. Image and code below (using @FranzHahn's
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,'.');
scatterhist(x,y,'Direction','out')