How to plot max, min and average over a histogram?

I have the following code that plots me a histogram:
% 1st GRAPH
figure(2)
hold on
a = connected_sites(:,3);
n = histc(a,1:nr_BBU);
max1 = max(n); % Max. valor
min1 = min(n); % Min. valor
avg1 = mean(n); % Valor medio
std1 = std(n); % Desvi. estándar
bar(1:nr_BBU,n)
title('Histogram distribution pool')
plot(1:nr_BBU,max1,'r.' ,'MarkerSize',15) %
set(gca,'XTick',1:nr_BBU)
xlabel('BBU Pool ')
ylabel('Nº of RRHs Connected');
legend({'BBU', 'Max1'},'AutoUpdate','off', 'Location', 'northeast')
And I get the desired histogram with an indicator for maximum values, but I would like to plot over also the minimum values, and the average.
Unfortunately I am quite as plotting is concerned and I can't get it. Any hints? Maybe it would be better to over plot a boxplot indicating the min, max and average??? I also can't get it to work.

댓글 수: 2

Hint:
Repeat this line but substitude the min and mean values for the max value within the line.
plot(1:nr_BBU, max1, 'r.' , 'MarkerSize', 15) %
% ^^^^ max value
Thank you so much!!! How easy would it be to over plot a boxplot ?

댓글을 달려면 로그인하십시오.

 채택된 답변

Adam Danz
Adam Danz 2020년 3월 8일
편집: Adam Danz 2020년 3월 8일

0 개 추천

(continuing from comment section under the question)
To show the min or mean, substitute those values in for the max value in the line below.
plot(1:nr_BBU, max1, 'r.' , 'MarkerSize', 15) %
% ^^^^ max value
How easy would it be to over plot a boxplot ?
A boxplot isn't what you're looking for. A boxplot shows the quartile ranges, not the max and min. You could, however, use a vertical errorbar.
data = randi(20,1,6);
bar(1:size(data,2), data, 'DisplayName', 'Data')
minData = min(data);
maxData = max(data);
meanData = mean(data);
hold on
errorbar(size(data,2)+1, meanData, meanData-minData, maxData-meanData, '-d', 'Vertical', ...
'LineWidth', 2, 'MarkerSize', 10, 'DisplayName', '[min, mean, max]')
legend()
or horizontal reference lines
data = randi(20,1,6);
bar(1:size(data,2), data, 'DisplayName', 'Data')
minData = min(data);
maxData = max(data);
meanData = mean(data);
yline(minData, 'k-', 'Minimum')
yline(maxData, 'k-', 'Maximum')
yline(meanData, 'k-', 'Mean')
ylim([0, maxData+2])

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

제품

릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by