Calculating how many runs die out

1 回表示 (過去 30 日間)
KJones
KJones 2016 年 11 月 12 日
編集済み: Star Strider 2016 年 11 月 12 日
I want to calculate how many runs die out out of k amount of runs. This doesn't work. How can i make it so the amount of runs dying out a vector where its 1 when it dies out or 0 when it doesnt?
A=createsrandomnetwork(10,1);
I=zeros(10,1);
positions=[1,1];
I(positions)=1;
v=zeros(1,10); %Vector which proportion value will be saved into
n=numel(I); %n=number of array elements
for k=1:10
dieout=zeros(10,k);
for i=1:10
a = rand(10);
R = triu(a) + triu(a,1)';
H=R>0.1; %Matrix with % chance of passing on infection
P=A.*H; %New Network Matrix including the probability
P(logical(eye(size(P)))) = 0; %makes sure the diagonal is 0 then people can recover
I=P*I; %New Network Matrix times the Vector of Infected
v(i)=nnz(I)/n %Proportion infected at time i
if sum(I)==0
dieout(k)=1
break
end
end
end

回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by