Multiple histograms and how to measure fwhm?
8 次查看(过去 30 天)
显示 更早的评论
I have 1 to 144 columns.
I want to draw 144 gaussian histograms fitting according to the column and find the positions of 144 FWHM and Peak.
Each column has a different row size.
What should I do?
0 个评论
采纳的回答
Star Strider
2021-12-14
Try this —
M1 = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/833435/1to10_30s_15mm_diff_pivoted.txt')
% figure
% hold on
% for k = 1:size(M1,2)
% subplot(12,12,k)
% hf{k} = histfit(M1(:,k)); % Distribution Plot
% [pks{k},locs{k},fwhm{k},prm{k}] = findpeaks(hf{k}(2).YData, hf{k}(2).XData);
% pd{k} = fitdist(M1(:,k), 'Normal'); % Parameters
% grid
% title(sprintf('Column #%3d (\\mu = %5.2f, \\sigma = %5.2f FWHM = %7.2f)',k, pd{k}.mu, pd{k}.sigma,fwhm{k}))
% end
figure
hold on
for k = 1:size(M1,2)
subplot(122,2,k)
hf{k} = histfit(M1(:,k)); % Distribution Plot
[pks{k},locs{k},fwhm{k},prm{k}] = findpeaks(hf{k}(2).YData, hf{k}(2).XData);
pd{k} = fitdist(M1(:,k), 'Normal'); % Parameters
grid
title(sprintf('Column #%3d (\\mu = %5.2f, \\sigma = %5.2f FWHM = %7.2f)',k, pd{k}.mu, pd{k}.sigma,fwhm{k}))
end
hold off
figure
hold on
for k = 1:24:size(M1,2)
subplot(3,2,ceil(k/24))
hf{k} = histfit(M1(:,k)); % Distribution Plot
[pks{k},locs{k},fwhm{k},prm{k}] = findpeaks(hf{k}(2).YData, hf{k}(2).XData);
pd{k} = fitdist(M1(:,k), 'Normal'); % Parameters
grid
title(sprintf('Column #%3d (\\mu = %5.2f, \\sigma = %5.2f FWHM = %7.2f)',k, pd{k}.mu, pd{k}.sigma,fwhm{k}))
end
hold off
.
4 个评论
Star Strider
2021-12-14
‘However, what I want is that when drawing a histogram, the Gaussian fitted graph will be different depending on the bin size.’
The Gaussian (or any other) fit actually had nothing to do with the histogram or bin size. It is entirely independent of it. From the histfit documentation Algorithms section:
- histfit uses fitdist to fit a distribution to data. Use fitdist to obtain parameters used in fitting.
‘Therefore, the FWHM and Peak (mean) of the fitting graph will also differ depending on the bin size.I want to know how much the numerical values change according to the bin size.’
Again, the bin size of the histogram has nothing to do with the distribution fit. It is only there for convenience, so that the fitted curve can be visually compared to the histogram. It is possible to use the histogram frequencies, bin locations, and nonlinear optimisation functions to fit a Gaussian (or any other distribution) curve to the histogram (this has been a topic of several previous Answers posts, some of which I responded to), however that is not accurate (does not produce the same results as directly calculating the mean and std and using them to draw the curve) and does not produce the same results as directly estimating the parameters using fitdist.
.
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!