normalize a histogram in pdf mode

4 次查看(过去 30 天)
MG
MG 2015-11-14
回答: the cyclist 2016-12-27
I am trying to normalize my histograms so that my gaussian curves can fit over them (right now, the histograms and gaussians are not on the same scale so the gaussians look really tiny. How do I fix this? I tried doing histogram(midterm,bins)./sum(histogram(midterm,bins)) but matlab didn't like that and said "Undefined function 'sum' for input arguments of type 'matlab.graphics.chart.primitive.Histogram'."
[num, txt, raw] = xlsread('grades.xlsx')
midterm = num(:,2);
t = tabulate(midterm);
scores = t(:,1);
counts = t(:,2);
assign = num(:,1);
bins = 0:15;
firstp = makeNormalDis(13.8306,1.3311);
secondp = makeNormalDis(10.7675,1.9410);
x = [0,15];
figure;
a = histogram(midterm, bins); hold on;
b = histogram(assign, bins);
fplot(firstp, x, 'r');
set(findobj(gca, 'Type', 'Line', 'Color', 'r'), 'LineWidth', 1.5);
fplot(secondp, x, 'b');
set(findobj(gca, 'Type', 'Line', 'Color', 'b'), 'LineWidth', 1.5); hold off
set(gca,'XTick',bins);
ylabel('Normalized PDF');
xlabel('Grades');
legend('Midterm', 'Assignment 1', 'Location', 'northwest');
grid on;

回答(1 个)

the cyclist
the cyclist 2016-12-27
Set the Normalization property of the histogram object. Here is an example:
h = histogram(randn(100000,1));
h.Normalization='probability'

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by