How to plot a normal distribution graph to fit a bar graph?

13 ビュー (過去 30 日間)
Rita
Rita 2016 年 11 月 24 日
コメント済み: Star Strider 2016 年 11 月 24 日
I have a bar graph which in the x-axis shows the edge centers and y-axis are N I would like to plot a normal distribution graph to fit the bar graph.Any suggestion?I know histfit but I have the N and edges only!Thanks
  2 件のコメント
Image Analyst
Image Analyst 2016 年 11 月 24 日
So you want to fit the Normal distribution to the binned counts instead of the actual original data that you took the histogram of? Why? And why do you have only the counts and edges and not the original data? You had to have had the original data to get the counts, right?
Rita
Rita 2016 年 11 月 24 日
Yes,I have calculated the percentage of the bins instead of counts for the yaxis.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2016 年 11 月 24 日
It’s easy enough to create your own version of histfit if you need to. See if this does what you want:
data = 0.5*randn(1,1000) + 2; % Create Data
mu = mean(data);
sd = std(data);
ndfcn = @(mu,sd,x) exp(-(x-mu).^2 ./ (2*sd^2)) /(sd*sqrt(2*pi)); % Standard Normal Distribution
[hc,edges] = histcounts(data, 25); % Histogram
ctrs = edges(1:length(edges)-1) + mean(diff(edges))/2; % Calculate Centres
ctrsx = linspace(min(ctrs), max(ctrs)); % High-Resolution Vector
sdnd = ndfcn(mu,sd,ctrsx); % Calculate Standard Normal Distribution
figure(1)
bar(ctrs, hc) % Plot Histogram
hold on
plot(ctrsx, sdnd*max(hc)/max(sdnd), '-r', 'LineWidth',2) % Plot Scaled Standard Normal Distribution
hold off
grid
Obviously, substitute your own data for my ‘data’ vector. I created mine to test my code.
  2 件のコメント
Rita
Rita 2016 年 11 月 24 日
Thanks a lot .
Star Strider
Star Strider 2016 年 11 月 24 日
My pleasure.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 11 月 24 日
I suggest reading the histfit() source and extracting the relevant portions of it -- using histfit() and figuring out a range with icdf and using pdf on the range

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by