Effacer les filtres
Effacer les filtres

Histogram Overlay with Controlled Bins

3 vues (au cours des 30 derniers jours)
David Polcari
David Polcari le 12 Mar 2013
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!
  1 commentaire
Walter Roberson
Walter Roberson le 12 Mar 2013
Please show your code.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 12 Mar 2013
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 commentaires
Image Analyst
Image Analyst le 15 Mar 2013
Modifié(e) : Image Analyst le 15 Mar 2013
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.
David Polcari
David Polcari le 28 Mar 2013
I've updated my question so you can understand what I was talking about. I'm sorry about the bar() function. As you guessed, I wanted to have bars. Thanks for the advice.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by