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