normalize a histogram in pdf mode
4 次查看(过去 30 天)
显示 更早的评论
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;
0 个评论
回答(1 个)
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'
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!