简体   繁体   中英

How do I plot a probability density graph on MATLAB

I have a set of randomly generated data that I want to plot on the probability density graph to show that they are 'bad' randomly generated data. I tried using ksdensity but the graph is not what I was looking for.

This is the graph I am looking for在此处输入图像描述

And here is how I generated my random numbers.

x = rand(1);
r = 3.99;
X1 = zeros(5000,1);

for i = 1:5000
for j = 1:1

    X1(i,j) = r*x*(1-x);

    %For next iteration%
    x = X1(i,j); 

end
end

disp(X1);
plot(X1);
title("Generated Data Sequence for 5000 Iterations");
xlabel("Iteration Number n"); ylabel("X_n");

Any help would be much appreciated!

This should do it. Add at the end:

h=linspace(min(X1(:)), max(X1(:)), 200)';
[n,~]=histc(X1(:), h);
pdfX=n/trapz(h,n);

figure
plot(h,pdfX)

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