필터 지우기
필터 지우기

Plotting gaussian on histograms

조회 수: 3 (최근 30일)
Kash022
Kash022 2016년 11월 2일
답변: Tian Tian 2017년 8월 4일
I have a hist distribution as shown. I now want to plot gaussians on top of this proportional to the number of occurences as shown. I am using the below code snippet to generate the histograms and then trying to plot the gaussians for each. The final output should look like a gaussian mixture which I am not getting. Please help! Thanks!
figure(3); subplot(1,5,1); clear x,y; [x,y] = hist(HW(1,:),[0:4]); stem(y,x); /* HW is a 16x16 matrix */
/**** for plotting gaussians ****/
x=[0:0.25:4];
for kk = 1:16
norm = pdf('Normal',x,HW(1,kk),0.25); /* my mean should be HW(1,kk) with sigma=0.25 */
plot(x,norm);hold on;
end

답변 (2개)

Steven Lord
Steven Lord 2016년 11월 2일
Rather than calling hist, call histogram and tell it to use 'pdf' Normalization.
% Create histogram from sample data A
A = repelem(0:4, [1 4 6 4 1]);
h = histogram(A, 'Normalization', 'pdf');
% Customize Y axis tick location and labels
ax = ancestor(h, 'axes');
ax.YTick = (0:6)./16;
ax.YTickLabel = {'0/16', '1/16', '2/16', '3/16', '4/16', '5/16', '6/16'};
  댓글 수: 2
Kash022
Kash022 2016년 11월 3일
It does not plot the gaussian mixture. Simply the histograms have been plotted which I don't need. I just need to see the gaussian pdfs overlapping with one another for given mu and sigma.
Kash022
Kash022 2016년 11월 3일
I have tried using the normpdf as shown below but do not get any output.
A = repelem(0:4, [1 4 6 4 1]);
for i = 1:size(A,2)
norm(i) = normpdf(A(i),HW(1,i),0.25);
plot(A(i),norm(i));
end

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


Tian Tian
Tian Tian 2017년 8월 4일
Hi Kash022,was your problem get solved? I also need to apply Gaussian filter to a histogram plot and find smoothed peaks. Could you please give me some ideas on applying Gaussian filter? Which code did you use? Many thanks. Tian

Community Treasure Hunt

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

Start Hunting!

Translated by