0

我有一个矩阵A (100,5),其中每一行都是模拟的结果 (n=100)。

我想绘制/“记录” A中的最大值小于 0.40 的模拟的累积比例。我设想的图有纵轴,其中值范围从 0 到 100%,横轴是模拟次数。

最终,我在同一张图上绘制了几个场景,其中至少有一个场景将在 100 次模拟标记处达到 100% 的累积比例。

下面的代码是我已经走了多远,但我无法降低累积比例。我不认为我的矩阵C是我正在寻找的。

干杯。

ts=1:1:100;
% Create A where all rows sum to 1
A = rand(100, 5); % @Nzbuu http://stackoverflow.com/q/9312850/1670053 for this ex 
rowsum = sum(A,2);
A = bsxfun(@rdivide, A, rowsum);

% Create a vector from A where each elements records whether the max value was less 
% than 0.40 (value = 0) or greater than 0.40 (value = 1)
counts = zeros(100,1);
for i = 1:100
    if max(A(i,:)) < 0.40
        counts(i) = 0;
    else
        counts(i) = 1;
    end;
end;

B = cumsum(counts); % Get the cumulative sum of counts
C = B/100
plot(ts, C)
4

0 回答 0