Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Histogram in MATLAB

  1. Jan 31, 2010 #1
    I am having some trouble deciphering how to plot a histogram in MATLAB. My main problem is that I want the x-axis labels to line up with the tick marks. I do NOT want the labels centered and under the bars themselves.

    I have been looking into the histc() function http://www.mathworks.com/access/helpdesk/help/techdoc/ref/hist.html", but have not figured out how to make it plot properly (with bin-edge labels under tick marks).

    Anyone know how to do this?
    Last edited by a moderator: Apr 24, 2017
  2. jcsd
  3. Jan 31, 2010 #2
    Is there any particular reason why you want to offset the tick marks in this way?
  4. Jan 31, 2010 #3
    Hi shoehorn. Yes. That is how I think it should be presented :)
    If 10 values fall between 20 and 25, then 20 should be the left mark and 25 should be the right mark and the column should rise up between the 2.

    Like http://www.treeplan.com/BetterHistogram_20041117_1555.htm" [Broken] except that I tried this procedure and it does not work reliably every time.

    I don't know; I guess I must be insane. I have been looking online for hours. I am surprised that nobody else think that they should be plotted like this. I just checked my textbook's solution manual too and they draw them with the bin values centered under the bar. But that is ambiguous to me. Does that value represent the max or min of the interval? And why should one have to go looking for the interval size? Why should they have to calculate it? These are rhetorical questions of course.... I just think that Plots should be crystal clear so the average bear can read them.
    Last edited by a moderator: May 4, 2017
  5. Feb 1, 2010 #4
    Can anyone confirm if this is even possible? Thanks!
  6. Feb 6, 2010 #5
    I did it in Excel for anyone who cares. It was a PITA, but worth it I think. I will post a guide on how to do it once I complete it.

  7. Mar 27, 2010 #6
    histogram program will be there which i used...plz try it
    i=imread(image path);
    for x=1:r
    for y=1:c
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook