How can I bin a set of data probability and plot it as a bar chart ?

17 次查看(过去 30 天)
I have a set of observed data of 3 years of hourly measurements "x" (25920x1 double) with min = 0.00003484 and max = 3.8787 ;
I want to plot a figure that has the following characteristics:
1. x axis = x values, y axis = probability density
2. X should be binned for one month and plotted as a bar chart (look like a bar chart)
3. A normal pdf (based on the mean and std of the observed data) must be plotted
This is in order to compare the existing data and a normal dist or how well the fit in the graph.
I don't even know how to start, how can I do this? Any idea? I am having trouble binning the data and plotting it as a bar chart of the pdf. The normal pdf plotting is not an issue

采纳的回答

the cyclist
the cyclist 2015-9-16
If you have the Statistic and Machine Learning Toolbox, you could use the histfit command.

更多回答(1 个)

Image Analyst
Image Analyst 2015-9-16
Decide how many bins you want and then call histcounts. For example (untested)
x = 4*randn(1, 10000);
numBins = 30;
[counts, edges] = histcounts(x, numBins);
binWidth = edges(2)-edges(1);
binCenters = edges(1:end-1) + binWidth/2;
bar(binCenters, counts, 'BarWidth', 1, 'FaceColor', 'b');
grid on;
To get the PDF, divide counts by the total number of counts. Then do the other stuff - if you still have trouble then write back.

类别

Help CenterFile Exchange 中查找有关 Bar Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by