A question about the histograms please
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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
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
MAHMOUD ALZIOUD
on 14 Dec 2017
Image Analyst
on 14 Dec 2017
Simply multiply by 100! (Did you look at the help documentation?)
histObject = histogram(tandem,nbins,'Normalization','probability')
percentages = 100 * histObject.Values
Steven Lord
on 14 Dec 2017
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.
MAHMOUD ALZIOUD
on 14 Dec 2017
MAHMOUD ALZIOUD
on 14 Dec 2017
Edited: MAHMOUD ALZIOUD
on 14 Dec 2017
Image Analyst
on 14 Dec 2017
Try this:
edges = linspace(6000, 82000, 41); % 41 edges for 40 bins.
histObject =histogram(tandem{K}, edges, 'Normalization', 'probability')
MAHMOUD ALZIOUD
on 14 Dec 2017
the cyclist
on 14 Dec 2017
Edited: the cyclist
on 14 Dec 2017
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.
MAHMOUD ALZIOUD
on 14 Dec 2017
the cyclist
on 14 Dec 2017
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?)
MAHMOUD ALZIOUD
on 14 Dec 2017
Image Analyst
on 14 Dec 2017
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.
MAHMOUD ALZIOUD
on 14 Dec 2017
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!