lundi 18 novembre 2019

randomly distribute nodes in groups and calculate the probability distribution of nodes number in every group

Suppose there are 10000 nodes and 10 groups. I can first randomly distribute all nodes in 10 groups randomly and count the node numbers in every group:

for j=1:10 
for i=1:10
 N=10000;% the whole node number is 10000
 Test=randi([1,10],1,N);%1000 nodes are randomly distributed in the group 1 to 10
 M=length(find(Test==i));%node number in every group
 fprintf('group %d has %d nodes ,the frequency is %f\n',i,M,M/N)
end
 B(j)=sum(Test==i);
end
bar(B) 

Now I want to repeat this process above for 1000 times and then count the times that groups have the a specific node number such as how many time that a group got exact 1000 nodes in it. And summarize the possible group's node number (1-10000) and their corresponding number of times in bar chart.




Aucun commentaire:

Enregistrer un commentaire