【问题标题】:Random number distribution随机数分布
【发布时间】:2014-03-28 19:22:54
【问题描述】:

我只是想知道如何在 matlab 图像处理中使用 randseed 而不是 randn

我想稍后使用 x,y 的质心来映射对象随时间的位置。

另外,我可以使用什么函数使生成的值能够这样做?

clear all

% Define image size
N = 300; 

%define Initial object point
X = 150;
Y = 150;

%Number of frames
duration = 10;

for T=1:duration
    % Set up rand image. Process and measurement noise
    Image = 0.4*rand(N);  %distabunce

    % Define object position & size
    X = X+10*randn;
    Y = Y+10*randn;
    Size_radius = 5;
    filter = BuildFilter(Size_radius);

    for i = 1:N
        for j = 1:N
            if (sqrt((i-X).^2+(j-Y).^2) < Size_radius)
                Image(i,j) = 1;
            end
        end
    end


    figure(1)
    %subplot(2,2,1)
    title('Caption1')
    imagesc(Image);
    colormap(gray);
    axis image;
    pause(0.1);

end

【问题讨论】:

  • 你想通过替换 randn 来达到什么目的?
  • 是的,所以我可以在模拟程序时使用相同的随机数,有人告诉我 randseed 是最好的选择

标签: matlab random


【解决方案1】:

您显然要求编写可重现和确定性的模拟。为此,您需要手动配置种子。

  • 使用 randstream 而不是 rand,为模型的每个独立部分使用一个流。
  • 将种子作为运行配置的一部分,每次迭代一个种子。
  • 多次使用相同的种子运行模拟,它必须产生完全相同(不是平均,精确到最后一位)的结果。现在您的模拟具有可重复性和确定性。

我建议在实施任何事情之前阅读该主题:

【讨论】:

    猜你喜欢
    • 2016-11-09
    • 2010-09-16
    • 1970-01-01
    • 1970-01-01
    • 2012-03-10
    • 2021-12-28
    • 2011-08-08
    • 1970-01-01
    • 2017-12-28
    相关资源
    最近更新 更多