

I figure you can make the addition below yourself when needed. I also used the 'Normalization', 'probability' option from the histogram function, and set the y axis to also show percentages. Most important is the 'HorizontalAlignment' option, and the distance to the bars. Putting the text at the right location may require some tweaking. % set ylim to fit all text (otherwise text is outside axes) Text(ax, bin_centers, txt_heigts, txt_labels, 'HorizontalAlignment', 'center') Txt_labels(end) = % remove last cell, is empty because of split. Txt_heigts = bin_props + 0.01 % put the text slightly above the bar H = histogram(x, 'BinEdges', edges, 'Normalization', 'Probability') Īx.XTickLabel = sprintf('%.1f to %.1f\n', labels) Īx.YTickLabel = sprintf('%i%%', (str2double(a)*100)), ax.YTickLabel, 'UniformOutput', false) īin_props = h.BinCounts/numel(x) % determine probabilities per bin in axis unitsīin_centers = ax.XTick(1:end-1) % get the bin centers % create vector with labels (for XTickLabel. See the comments in the code for explanation. You can use the histogram function, and then set the XTick positions and XTickLabels accordingly.
