How to set the Bin width of the histogram ?

571 views (last 30 days)
karanvir sidhu
karanvir sidhu on 13 Jun 2019
Answered: Paramjit Yadav on 8 Jul 2021
I am setting the bin width to 0.05 as can be in seen in the code snipet below
h1 = histogram(Data);
h1.Normalization = 'probability';
h1.BinWidth = 0.05;
But the histogram does not set the bin width to 0.05. It varies every time I run the function.
Please help.
  1 Comment
the cyclist
the cyclist on 13 Jun 2019
This code set the bin width to 0.05 for me, as expected.
Data = rand(100,1);
h1 = histogram(Data);
h1.Normalization = 'probability';
h1.BinWidth = 0.05;
Can you upload an example of the variable Data that exhibits the problem?

Sign in to comment.

Answers (2)

Paramjit Yadav
Paramjit Yadav on 8 Jul 2021
How to set the bin width and bin edges simulataneously. Please help.
  2 Comments
Steven Lord
Steven Lord on 8 Jul 2021
If you're explicitly setting the bin edges, that fixes the bin widths (potentially to non-uniform values.) So just set the edges.

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!