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 CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by