필터 지우기
필터 지우기

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 CenterFile Exchange에서 ANOVA에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by