This issue might be caused due to the difference between the binLocations output of the imhist command and the x-axis scale for the bar graph. For example:
A = rand(1024);
[counts, binLocations] = imhist(A);
After executing the above code, examine the value of the binLocations variable. It would have a range between 0 to 1, while the histogram would have an x-axis between 0 to 255. Therefore, the following line of code:
would limit the bar graph to a range of 0 to 1, while the actual data is plotted on a range from 0 to 255. If you would like to show the full range of the bar graph, the following may work better:
However, if you would like to scale the x-axis of the bar graph correctly between 0 and 1, the following might work better:
For more information, please refer to the MATLAB documentation pages for bar , numel , and imhist .