简体   繁体   中英

How I can alter the probability of an event in Matlab?

I have a network with N = 5 nodes. The probability that a new connection exit node "Ni" is:

P(N1) = P(N2) = P(N3) = P(N4) = P(N5) = 1/5

And the sum of all P(Ni) = 1.

which is a uniform distribution. I would like, nodes N3 and N5 had more chance to leave the rest. For example:

P(N1) = P(N2) = P(N4) = 2/15

P(N3) = P(N5) = 3/10

And the sum of all P(Ni) = 1.

The code I am using now is this:

nodes = 21;
NODES=(1:nodes);
R=randperm(nodes);
nodeSource=NODES(R(1));
nodeDestin=NODES(R(2));

Thanks.

您可能想看看randsample

nodeSource = randsample(1:numel(P), numel(P), true, P)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM