Am I misusing hist/histogram?
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
Sorry if I get the terminologies wrong here, happy for someone to correct me.
I have an array 1x60000 double named "v", one third of the entries (20000) are 6, one third are 36 and one third are 216, scattered throughout.
I've been advised to use hist (and I've experimented with histogram) to get a 1x216 double, with the number of occurences of each entry will be shown by the value in that index.I have no interest in viewing the plot.
With the above, I'd expect to get an array with all zeros, except for a value of 20000 in positions 6, 36, and 216.
H = hist(v,216);
However, in H I get values of 20000 at position 1, 31, and 216.
I've made other arrays with 3 other values, 20000 of each, distributed both randomly and uniformly, but always the result of a value 20000 at positions 1, 31, and 216.
Can someone explain why, please, and help me get the values in the representative positions? In the future I'm looking to have many values distribulted randomly and will want to have an array showing the number of occurences of each value in the corresponding position of the output array.
Many thanks,
0 个评论
回答(1 个)
Steven Lord
2019-10-28
0 个投票
As the note at the top of the documentation page for the hist function states, hist is not recommended. Use histogram (or if you don't need the plot of the distribution, use histcounts.) If all your values are integers, you may want to specify the 'BinMethod' to be 'integers' when you call histcounts, so each integer has its own bin.
Why didn't hist give you the results you expected? If you have to use hist, call it with two output arguments and look at the bin centers (the second output argument.) They're not "nice" values.
1 个评论
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!