Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在matlab中显示randperm()是公平的_Matlab_Probability_Combinatorics - Fatal编程技术网

如何在matlab中显示randperm()是公平的

如何在matlab中显示randperm()是公平的,matlab,probability,combinatorics,Matlab,Probability,Combinatorics,假设,我想(从经验上)证明,来自matlab的randperm(n,k)确实从一组n个元素中产生大小为k的均匀分布随机样本。重复绘制后,如何绘制出现次数除以从N中绘制的k-子集总数的曲线?您可以简单地使用从randperm中绘制的索引来增加计数器向量 n=1e5; k=1e4; maxiter = 1e5; % This array will be used to count the number of times each integer has been drawn count=zeros

假设,我想(从经验上)证明,来自matlab的randperm(n,k)确实从一组n个元素中产生大小为k的均匀分布随机样本。重复绘制后,如何绘制出现次数除以从N中绘制的k-子集总数的曲线?

您可以简单地使用从
randperm
中绘制的索引来增加计数器向量

n=1e5;
k=1e4;
maxiter = 1e5;

% This array will be used to count the number of times each integer has been drawn
count=zeros(n,1);

for ii=1:maxiter
    p=randperm(n,k);
    % p is a vector of k distinct integers in the 1:n range
    % the array count will be incremented at indices given by p
    count(p)=count(p)+1;
end

% A total of k*maxiter integers has been drawn and they should be evenly
% distributed over n values
% The following vector should have values close to 1 for large values of maxiter
prob = count*n/(k*maxiter);

您可以简单地使用从
randperm
中提取的索引来增加计数器向量

n=1e5;
k=1e4;
maxiter = 1e5;

% This array will be used to count the number of times each integer has been drawn
count=zeros(n,1);

for ii=1:maxiter
    p=randperm(n,k);
    % p is a vector of k distinct integers in the 1:n range
    % the array count will be incremented at indices given by p
    count(p)=count(p)+1;
end

% A total of k*maxiter integers has been drawn and they should be evenly
% distributed over n values
% The following vector should have values close to 1 for large values of maxiter
prob = count*n/(k*maxiter);