# How to transform the normalized values of a histogram (i.e. the bars heights) in percentages?

9 Ansichten (letzte 30 Tage)
Sim am 8 Feb. 2023
Kommentiert: Star Strider am 8 Feb. 2023
How to transform the normalized values of this histogram (i.e. the bars heights) in percentages?
I should multiply the bars values by 100, but how to do it ? (maybe inside the "histogram" function)
a = [0 0 0 1 1 1 1 1 1 3 3 3 2 2 4 4 39 39 39 39 39 39 40 40 40 40 40 40 40 0 0 0 0 0 0 0 41 41 41];
histogram(a,'Normalization','probability')
This could be a workaround:
bar(histcounts(a)/(sum(histcounts(a)))*100)
BUT:
1. the bars are shifted towards right (why??)
2. I would like to still use the "histogram" function (if possible, obviously)
Any idea ?
##### 3 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Sim am 8 Feb. 2023
Bearbeitet: Sim am 8 Feb. 2023
Oh cool, thanks a lot @Les Beckham!! :-)
Les Beckham am 8 Feb. 2023
You are quite welcome.

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Star Strider am 8 Feb. 2023
Altering the histogram plot is likely not possible because the ‘Values’ vector is read-only.
The easiest approach is likely to re-plot the bar plot using the derived values —
a = [0 0 0 1 1 1 1 1 1 3 3 3 2 2 4 4 39 39 39 39 39 39 40 40 40 40 40 40 40 0 0 0 0 0 0 0 41 41 41];
figure
hh = histogram(a,'Normalization','probability');
xlabel('Centers')
ylabel('Probability')
Values = hh.Values*100;
Cntrs = hh.BinEdges(1:end-1) + diff(hh.BinEdges)/2;
figure
bar(Cntrs, Values)
xlabel('Centers')
ylabel('Percent')
.
##### 4 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
Sim am 8 Feb. 2023
@Star Strider Yes yes, true, many thanks for having presented a solution related to the histogram function, I am very grateful! (this is a way to learn/understand deeper the functions available in Matlab)
Star Strider am 8 Feb. 2023
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Histograms finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by