Histogram Overlay with Controlled Bins
3 次查看(过去 30 天)
显示 更早的评论
Hi all, I need some help making as histogram. I have two data sets of 51 by 101. I would like to create a histogram similar to what I could make in excel. I would like to control the bin values themselves as opposed to the number of bins. More specifically, I want the following:
Bins: 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50
Where bin 1 goes from 0.00-0.24, bin 2 goes 0.25-50, etc.
I would also like to know how many values from my datasets fit into each bin. Finally, I would like to plot an overlay of these two histograms so I can compare both datasets. However, if two bars are overlayed, I'd like to be able to see the bar behind also. Thank you very much for your help!
采纳的回答
Image Analyst
2013-3-12
Use plot() instead of bar(). With plot(), it's easier to see two plots at the same time and easy to specify the color of each.
[counts1, values1] = hist(data(:), numberOfBins1);
[counts2, values2] = hist(data(:), numberOfBins2);
plot(values1, count1, 'r-');
hold on;
plot(values2, count2, 'b-');
3 个评论
Image Analyst
2013-3-15
编辑:Image Analyst
2013-3-15
I don't have your dataset so I can't test your code. True, the bins may be different - their range and centers - but plot() does not care about that. Bar() would, but plot() doesn't(). So when you said "this works but not fully" you were referring to YOUR code, not mine. Any reason why you didn't use mine, where I explicitly said to use plot() and to not use bar()? If it's because you want bars instead of a line plot, then you need to use histc() instead of hist() so you can specify fixed bin locations instead of just relying on whatever each hist() happens to pick.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!