gpt4 book ai didi

matlab - 二维中均匀分布的点

转载 作者:行者123 更新时间:2023-12-02 20:54:07 40 4
gpt4 key购买 nike

如何生成二维均匀分布的点?我测试了这段代码,但我不想要这个,因为在这段代码中 xy 是统一的,但是 (x,y) 不统一。

X=rand(2,N);
x= X(1,:);
y=X(2,:);
figure;
plot(x,y,'.');

最佳答案

您的代码确实对 2D 空间进行了统一采样。但是在 Matlab 中还有 unifrnd 方法,它对 n 维空间进行采样。

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

关于matlab - 二维中均匀分布的点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41040216/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com