poissrnd(7,100,1)
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
r=poissrnd(7,100,1)
tabulate(r)
This produces a 3 column table, the percent is not CDF. Is there an easy way to create a 4th column of the CDF?
Thanks
0 Commenti
Risposte (1)
Shaik mohammed ghouse basha
il 30 Mag 2023
Modificato: Shaik mohammed ghouse basha
il 30 Mag 2023
Hello,
As per my understanding of the question you have generated random numbers from poisson distribution with rate parameter (lambda) 7 in a 100 X 1 array. After generating you tabulated them which shows three columns consisting of value, count, percent. Third column shows the percent of each value and not CDF. Now you want to display CDF as the fourth column.
CDF measures probability of a random variable taking on a specific value or a value less than or equal to a given value. For a value the CDF is the sum of all individual probabilities of values less than or equal to given value.
In order to get this we first calculate the probabilities of each value and then add them in a way similar to prefix sum array.
lambda = 7;
x = 100;
y = 1;
r = poissrnd(lambda, x, y);
% r has the random numbers generated from poisson distribution.
T = tabulate(r);
% T stores value, its count, its frequency.
P = T(:, 2)/sum(T(:, 2));
%P is a column vector which is made by dividing the count of each value
%with sum of all counts. This is nothing but probability of each value
cdf = cumsum(P);
%cumsum is used to add the probabilities similar to prefix sum. For ith
%element in cdf we add all values form 1 to i in P
T = [T, cdf];
%add generated cdf as a column to T
disp(T);
If you want fourth column to be CDF percent instead of probability, you can just multiply 100 when P column vector is calculated.
For further reference of functions used in code you can go throguh these links:
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!