A question about the histograms please

Hi everyone, As can be seen in the attached image, my histogram is built using counts, I WROTE THE FOLLOWING CODE TO CONVERT COUNTS TO %, how can i know exactly the percent of each load bin
figure,
>> histogram([tandem{K}]);
ylabels = get(gca, 'YTickLabel');
ylabels = linspace(0,100,length(ylabels));
set(gca,'YTickLabel',ylabels);

Answers (1)

the cyclist
the cyclist on 14 Dec 2017
Edited: the cyclist on 14 Dec 2017
As described in the documentation for the histogram function, you can used the 'Normalization' input parameter:
histogram(tandem{K},nbins,'Normalization','probability')

13 Comments

thank you very much, this worked, but i still have to know what is the percentage of each load bin, because i am trying to make a table of each load bin with its %.
Simply multiply by 100! (Did you look at the help documentation?)
histObject = histogram(tandem,nbins,'Normalization','probability')
percentages = 100 * histObject.Values
Call histogram and specify the 'probability' Normalization as the cyclist showed, but specify an output argument when you call it. Then get the Values property of the handle returned from histogram. Alternately, if you don't need the graphics object call histcounts with that same Normalization option.
yes i just tried it and it worked, one last question please, what if i want to define the ranges of bins as follows, 4o bins with a range of 6000:2000:82000, where can i put this piece of data in the code?
this is my code: the missing piece is how to tell him make me 40 bins with 2000 of width for each bin and starting from 6000 to 82000
figure
histObject =histogram(tandem{K},40,'Normalization','probability')
percentages = 100 * histObject.Values
xlabel('Load in Kips')
ylabel('Normalized Percentages')
title(['ALS for C9 Tandem For Month ',num2str(months),' ', 'Station' ,' ', num2str(stations)])
Try this:
edges = linspace(6000, 82000, 41); % 41 edges for 40 bins.
histObject =histogram(tandem{K}, edges, 'Normalization', 'probability')
i tried it and i lost the histogram, it became with no data in it !
I'm confused. It sounds like you are trying to specify values that are in the range on the y-axis. You should be specifying the edges of the bins with the values of the x axis. So maybe you just want
linspace(0,40,41)
instead of what you did.
You also don't really need to use linspace for that. The vector
0:40
will give the same.
Dear, I am trying to organize the bins based on the x-axes values, my x-axis must start with 0 to 82000, in which this range must hold 40 bins of the histogram, is it clearer now?
OK, then
linspace(0,82000,41)
should work. But the figure you posted here has x-axis that are in the range 0-60 ("Load in Kips"), so I'm still a bit confused. (Maybe you just relabeled the X tick labels?)
yes you are right, the thing is i have 10 text files i am analyzing, one of the is the attached image in which the range ends at 60 Kips, the other files they end at 80 kips (kips means one thousand pounds), that is why i need to unite the whole 10 figures in one common range.
Is your data in the range 0 to 80, or 0 to 80,000? Either way, just use linspace and put in the overall min and overall max, and the number of bins you want to form the edges.
thank you guys for your very powerful help

This question is closed.

Asked:

on 14 Dec 2017

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!