Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.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中矩阵列的顺序读取_Matlab - Fatal编程技术网

MATLAB中矩阵列的顺序读取

MATLAB中矩阵列的顺序读取,matlab,Matlab,我最初的问题是创建一个场景,其中有一条特定长度的线(x=100),在特定位置有一个屏障(pos=50)。进行了多轮抽样,在这轮抽样中产生了特定数量的随机数(p)。生成的数字可以落在屏障的左侧或右侧。程序输出屏障左侧生成的最大数值与右侧生成的最小数值之间的差值。在这里可以更清楚地看到: 在本例中,系统创建了4个数字(a、b、c、d)。它将忽略a和d,并输出b和c之间的差值。本质上,它将输出仍然包含屏障的线的最小可能片段 我一直在使用的代码是: x = 100; % length of

我最初的问题是创建一个场景,其中有一条特定长度的线(x=100),在特定位置有一个屏障(pos=50)。进行了多轮抽样,在这轮抽样中产生了特定数量的随机数(p)。生成的数字可以落在屏障的左侧或右侧。程序输出屏障左侧生成的最大数值与右侧生成的最小数值之间的差值。在这里可以更清楚地看到:

在本例中,系统创建了4个数字(a、b、c、d)。它将忽略a和d,并输出b和c之间的差值。本质上,它将输出仍然包含屏障的线的最小可能片段

我一直在使用的代码是:

x = 100;       % length of the grid
pos = 50;      % position of the barrier
len1 = 0;      % left edge of the grid
len2 = x;      % right edge of the grid

sample = 1000; % number of samples to make
nn     = 1:12  % number of points to generate (will loop over these)

len = zeros(sample, length(nn)); % array to record the results

for n = 1:length(nn)                     % For each number of pts to generate
    numpts = nn(n);
    for i = 1:sample                     % For each round of sampling,
        p = round(rand(numpts,1) * x);   % generate 'numpts' random points.
        if any(p>pos)                    % If any are to the right of the barrier,
            pright = min(p(p>pos));      % pick the smallest.
        else
            pright = len2;
        end
        if any(p<pos)                    % If any are to the left of the barrier,
            pleft = max(p(p<pos));       % pick the largest.
        else
            pleft = len1;
        end
        len(i,n) = pright - pleft;       % Record the length of the interval.
    end
end
由此,我想为每个λ取1000个样本,但在每轮1000个样本中,所有1000个样本的随机数计数不再相同。相反,它取决于泊松分布。例如,在平均值1内,概率为:

0 - 0.3678
1 - 0.3678
2 - 0.1839
3 - 0.0613
4 - 0.0153
5 - 0.0030
6 - 0.0005
7 - 0.0001
8 - 0.0000
9 - 0.0000
10 - 0.0000
11 - 0.0000
12 - 0.0000
因此,对于第一轮的1000个样本,其中367个样本只生成1个数字,367个样本生成2个数字,183个样本生成3个数字,依此类推。然后,程序将使用从平均值2获得的新值重复此操作,依此类推。然后我想简单地收集所有片段大小(
pright-pleft
)到矩阵的一列中,一列表示λ的每个值

我知道我可以这样做:

amount = dist*sample
将泊松分布乘以样本大小,以获得每个数字生成的数量——然而,我真的很难理解如何将其合并到for循环中,并修改代码以满足解决这个新问题的需要。我也不知道如何读取矩阵上的一列来使用每个概率值来确定每种类型的RNG应该做多少

任何帮助都将不胜感激


安娜

如果您有统计工具箱,您可以使用
random
从已知pdf对象生成随机变量向量。更好的方法是跳过PDF步骤,使用
poissrnd
生成随机变量。将该值四舍五入到最接近的整数,然后调用
rand
,就像您刚才所做的那样。在循环中,只需在生成的泊松分布随机数向量上迭代

例如:

x = 100;       % length of the grid
pos = 50;      % position of the barrier
len1 = 0;      % left edge of the grid
len2 = x;      % right edge of the grid

sample = 1000; % number of samples to make
lambda = 1:12;  % lambdas

Rrnd = round(poissrnd(repmat(lambda,sample,1)));
len = zeros(size(Rrnd)); % array to record the results

for n = lambda;                         % For each number of pts to generate  
    for i = 1:sample                     % For each round of sampling,
        numpts = Rrnd(i,n);
        p = round(rand(numpts,1) * x);   % generate 'numpts' random points.
        len(i,n) = min([p(p>pos);len2]) - max([p(p<pos);len1]); % Record the length
    end
end
x=100;%网格长度
位置=50;%障碍物的位置
len1=0;%网格的左边缘
len2=x;%网格的右边缘
样本=1000;%要制作的样品数量
λ=1:12;%兰博达斯
Rrnd=圆形(泊松比(repmat(λ,样品1));
len=零(大小(Rrnd));%数组来记录结果
对于n=λ;%对于要生成的每个pts数
对于i=1:每轮抽样的样本百分比,
numpts=Rrnd(i,n);
p=四舍五入(兰特(整数,1)*x);%生成“numpts”随机点。

len(i,n)=min([p(p>pos);len2])-max([p(pHello,欢迎来到SO!很好你已经努力写了一个包含代码的详细问题。但是,至少对我来说,这是不清楚的。”这解决了一个问题,即在特定的位置有一条特定长度的线(x=100)和一个障碍物(pos=50)。”–你谈论的障碍是什么,长度是多少?请编辑你的问题,首先简要说明背景和背景,然后是具体问题,然后进入代码。谢谢你的欢迎。希望我的编辑能澄清一点。纯粹出于好奇:这方面的应用是什么?有什么关联吗给所谓的麦阿瑟“断棒模型”?你似乎在某种程度上分割一根类似于该模型的棍子。当然,可以与该模型得出相似之处——但我的模型本质上是生物性的。“线”代表一条线性染色体,“屏障”代表一个特定定位的DNA探针。生成的数字代表随机的染色体断裂染色体和我们正试图了解断裂频率的变化对仍然含有探针的碎片大小的影响。这似乎是完美的。谢谢。我没有考虑过这样做,也不知道PoSrNd的存在。没问题。我缩短了一点,因为当<代码>
x = 100;       % length of the grid
pos = 50;      % position of the barrier
len1 = 0;      % left edge of the grid
len2 = x;      % right edge of the grid

sample = 1000; % number of samples to make
lambda = 1:12;  % lambdas

Rrnd = round(poissrnd(repmat(lambda,sample,1)));
len = zeros(size(Rrnd)); % array to record the results

for n = lambda;                         % For each number of pts to generate  
    for i = 1:sample                     % For each round of sampling,
        numpts = Rrnd(i,n);
        p = round(rand(numpts,1) * x);   % generate 'numpts' random points.
        len(i,n) = min([p(p>pos);len2]) - max([p(p<pos);len1]); % Record the length
    end
end