Calculating how many runs die out
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!