フィルターのクリア

histfit function - how to create one bin for each unique value?

5 ビュー (過去 30 日間)
Erik Schiferle
Erik Schiferle 2021 年 4 月 2 日
コメント済み: Erik Schiferle 2021 年 4 月 5 日
Hi,
I am trying to use the histfit function. My goal is to modify the code below so that I can create a bin for each unique value from data in excel (not evenly spaced bins) and then still overlay the fits. Is this possible?
I've attached what the hist would look like (made in graphpad). But, my matlab plots look like those attached.
Thanks!
r = xlsread('Results.csv','B:B')
ax1 = subplot(3,1,1); % Left subplot
h=histfit(ax1,r,33,'inversegaussian')
title(ax1,'Inverse Gaussian')
h(1).FaceColor = [1 0 0]
h(2).Color = [.2 .2 .2];
ax2 = subplot(3,1,2); % Right subplot
h=histfit(ax2,r,33,'Rayleigh')
title(ax2,'Rayleigh')
h(1).FaceColor = [1 0 0]
h(2).Color = [.2 .2 .2];
ax2 = subplot(3,1,3); % Right subplot
h=histfit(ax2,r,33,'Rician')
title(ax2,'Rician')
h(1).FaceColor = [1 0 0]
h(2).Color = [.2 .2 .2];
%pd = fitdist(r,'Normal')

回答 (1 件)

Image Analyst
Image Analyst 2021 年 4 月 2 日
Did you try
edges = [unique(yourData(:)), inf];
theHistogram = histogram(yourData, edges);
  2 件のコメント
Erik Schiferle
Erik Schiferle 2021 年 4 月 5 日
Thanks for the suggestion!
The reason I tried to make histfit work at first is that it was very easy to switch back and forth between the overlaid distritbution plots... Is there an easy way to do this with histrogram?
I've rewritten using "histogram" below. Only issue now is that, if possible, Id like to make the bins "falsely" evenly sized. Ie the distance between the bins might be 0.01 to 1 and 1 to 10, but I'd like to make the bars the same width. I'm not sure if it would make sense to do this with the overlay of the distribution? Also, I can't seem to make the bin labels show up?
Thank you!
r = xlsread('Results.csv','B:B');
avg=mean(r);
stdeviation = std(r);
biggest =max(r);
biggest =biggest*1.05;
edgeswid = unique(r(:));
h=histogram(r,edgeswid);
h.FaceColor = [0 0 0];
h.EdgeColor = [0 0 0];
hold on
y = 0:0.00001:biggest;
mu = avg;
sigma = stdeviation;
f = exp(-(y-mu).^2./(2*sigma^2))./(sigma*sqrt(2*pi));
h =plot(y,f,'LineWidth',1,'Color','r');
Erik Schiferle
Erik Schiferle 2021 年 4 月 5 日
Here is an example CSV if that helps

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by