Подробности см. В комментариях к коду, в основном вы можете использовать patch
, чтобы выделить фон, и некоторую логическую индексацию, чтобы найти, какие ячейки находятся в пределах вашего порога 16,5% - 83,5%.
Здесь используются bar
и histcounts
для создания гистограммы, а не histogram
, так как вы получаете более полезные выходные данные и нам нужны промежуточные шаги перед построением графика.
rng(0); % for repeatable random numbers
x = normrnd( 0, 1, 1000, 1 ) * 10; % Create data
% Get the histogram counts with 50 bins
[hc, edges] = histcounts( x, 50 );
% Lower and upper bounds we're interested in highlighting
region = [0.165, 0.835];
% Cumulative percentage across the bins
pct = cumsum( hc ) / sum( hc );
% Index to get which meet our bounds
idx = pct >= region(1) & pct <= region(2);
% Set up the plot
x = (edges(1:end-1)+edges(2:end))/2;
maxY = 1.1*max(hc);
n = nnz(idx);
% Plot
figure; hold on
patch( [x(idx),fliplr(x(idx))], [zeros(1,n),ones(1,n)]*maxY, 'y', 'edgecolor', 'none' );
bar( x, hc );
hold off
ylim( [0, maxY] );
Результат:
