フィルターのクリア

Someone help me to fix the problem?

3 ビュー (過去 30 日間)
Onur Metin Mertaslan
Onur Metin Mertaslan 2020 年 5 月 7 日
Hello everyone, I need to create random numbers and find the poisson distribution and its pdf and the draw the plot of it, I try to do it this code but I am doing something wrong here, can someone help me to do it?
lambda =75;
for i=1:1000
r(i) = poissrnd(lambda);
end
P = poisspdf(r,lambda);
[M,V] = poisstat(lambda);
% bar(r,P,1);
% xlabel('Observation');
% ylabel('Probability');

採用された回答

Michael Soskind
Michael Soskind 2020 年 5 月 7 日
I think you need to use the unique function here. Something that is important to note is that the bar chart requires r to be unique values. In addition, because of that, you need to count the number of times that the counts occur. Also, because you want to plot the probability, you want to divide by the number of total occurences in the set. This is reflected in the code below:
% Generating the random dataset
lambda =75;
for i=1:1000
r(i) = poissrnd(lambda);
end
P = poisspdf(r,lambda);
[M,V] = poisstat(lambda);
counts = hist(r, unique(r)); % unique selects the number of unique elements
% hist counts the number of elements at each unique value
bar(unique(r), counts/1000) % bar chart plots the counts
% because you have 1000 elements, you divide counts by 1000 to get the probability
xlabel('Observation');
ylabel('Probability');
  1 件のコメント
Onur Metin Mertaslan
Onur Metin Mertaslan 2020 年 5 月 7 日
Thank you so much, I am quite new in Matlab and I could not able to fix the problem. Thanks for your help!

サインインしてコメントする。

その他の回答 (0 件)

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by