how to organize my histogram please

Dear All, I have a column matrix Called (Load), it represents the Loads of Vehicles, the dimension for this matrix is 1000 by 1, I was ytrying to draw the histogram for this matrix using the following code, it means I need 39 Load Bins in the histogram, my question is: how can I tell MATLAB to draw this histogram with 39 bins but starting from 3000 ending with 41000? I need to define the boundaries and number of bins together. my code is:
histObject=histogram(Load,39,'Normalization','probability');
Please help

 Accepted Answer

Try this:
edges = linspace(3000, 41000, 40); % Define 39 Bins With 40 Edges
histObject = histogram(Load, edges, 'Normalization','probability');

9 Comments

I did, look what it gave me ! this is not a histogram, any idea please?

I cannot get any information from your .fig file.

My best guess is that none of your data are between the limits you set.

Consider:

Data = randi(50000, 100, 1);
edges = linspace(3000, 41000, 40);                      % Define 39 Bins With 40 Edges
histogram(Data, edges)

This produces an appropriate histogram, with the appropriate edges and 39 bins.

I Will try it now, thank you, i checked my data and most of it between 15000 and 18000 which is the peak. i need the bins to be from 3000 to 4100 with 1000 increment
i tried your code, youe x-axis is from 0 to 45000, how can i make it the same but starting from 3000 to 41000 with each bin width is 1000, that is 39 bins

When I add a get call to my previous code: Data =

randi(50000, 100, 1);
edges = linspace(3000, 41000, 40);                      % Define 39 Bins With 40 Edges
histogram(Data, edges)
XL = get(gca,'XLim')

the result is:

XL =
        1100       42900

so the result is appropriate, and does not extend from 0 to 45000. The 'BinEdges' and 'BinLimits' correspond to those I set in my code. The 'BinEdges' returned by:

BE = Ax.Children.BinEdges

coresponds to those I set in my code. The width of each bin is about 974.36, since those are the requirements you set.

You may need to experiment with the number of bins you want and how to define them. I am using the information you provided, to produce the histogram result you specified.

Dear Brother, attached is my data file, a text file, composed of 1000 inputs, i tried the last thing you said but still didnt work, can you please take a look at the file

What is your definition of didn’t work?

This code:

filename = 'test.txt';
Load = load(filename);
edges = linspace(3000, 41000, 40);                                      % Define 39 Bins With 40 Edges
histObject = histogram(Load, edges, 'Normalization','probability');

produces this plot:

It really keeps giving me an empty chart even i wrote the same as you did. any way thank you very much for your help
Star Strider
Star Strider on 24 Apr 2018
Edited: Star Strider on 24 Apr 2018

As always, my pleasure.

I am using R2018a if that is important.

I would suggest that you see if the histfit function will do what you want. (I have not used it here.)

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!