I have plotted a histogram with values from 0-30 with a total of 8 class intervals. I want to display bin edges but I have version R2014 and it does not have histcounts for input of type double. Is there another way of doing this without histcounts?

2 views (last 30 days)
load sizes2.txt
n=length(sizes); %num of rows
results= sizes2(:,1) %makes an array of data in sizes 2
b=sort(results) % sorts numbers in data from smallest to largest
k=1+3.22*log10(n) % calculates Sturge's value for possible class intervals
k1= round(k) % truncate; use round() if to nearest integer
fprintf('The suggested number of class intervals rounded to nearest integer is %d\n', k1 );
m=hist(sizes2,k1)
hist(b,k1)

Answers (1)

Cam Salzberger
Cam Salzberger on 4 Sep 2015
Hello Jackie,
I understand that you are looking to determine the edge-values of the bins in MATLAB R2014a. In your case, the bins all have the same width, so you can determine that from the centers output that you can get from the hist function. If the bins did not have the same width, then you would have to give the bin edges as an input to the hist function, so the point would become moot.
If you just modify your code to the following, the edge values will be in the binEdges variable, and you can even change the x-axis tick marks to display those values.
[m,centers]=hist(sizes2,k1);
binWidth = centers(2)-centers(1);
binEdges = [centers-binWidth/2 centers(end)+binWidth/2];
hist(b,k1)
set(gca,'XTick',binEdges)
Also, you probably want to change the second line to:
n=length(sizes2);
to access the correct variable.
I hope that this helps!
-Cam

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!