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

5 次查看(过去 30 天)
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');

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by