在下面的程序中,我想改变它的值Trial
并想运行它一千次,计算每次试验中出现的N
in (即迭代)。D
N = 10;
B = eye(N);
C = zeros(1,N);
p = [0.1 0.2 0.4];
count = 1;
Trial = 1;
for t = 1:Trial
for q = 1:numel(p)
for ii=1:N
X = B;
X(ii, rand(size(p))<p(q)) = 0;
A = max(bsxfun(@minus, X,C), 0);
[~,idx] = max(A(sum(A,2)==1,:), [], 2);
if ~isempty(idx)
C(idx) = 1;
end
end
D(count,:) = sum(C);
count = count+1;
end
end
我知道如何计算N
in的出现次数D
。问题是对于Trial = 2
,数组D
变成 6x1,但我希望它在每次迭代中始终保持 3x1。我怎么做?