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

4 visualizaciones (últimos 30 días)
Erik Schiferle
Erik Schiferle el 2 de Abr. de 2021
Comentada: Erik Schiferle el 5 de Abr. de 2021
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')

Respuestas (1)

Image Analyst
Image Analyst el 2 de Abr. de 2021
Did you try
edges = [unique(yourData(:)), inf];
theHistogram = histogram(yourData, edges);
  2 comentarios
Erik Schiferle
Erik Schiferle el 5 de Abr. de 2021
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 el 5 de Abr. de 2021
Here is an example CSV if that helps

Iniciar sesión para comentar.

Categorías

Más información sobre Bar Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by