Histogram Overlay with Controlled Bins
1 回表示 (過去 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 で Histograms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!