Is there a way to get the fitted curve generated by histfit without it being plotted? I want the curve it generates, but I don't want the plot it generates. Thanks times a million in advance.
Bill

 Respuesta aceptada

Star Strider
Star Strider el 26 de Ag. de 2020
Try this:
r = normrnd(10,1,100,1); % Create Data
h = histfit(r,6);
set(gcf,'Visible','off')
CurveX = h(2).XData;
CurveY = h(2).YData;
.

8 comentarios

Otis
Otis el 26 de Ag. de 2020
I thought about doing something like that, but I would prefer to not have to have any graphics generated. I came across fitdist, so I ended up doing something like the following:
x = (-6:0.1:6);
r = randn(1024,1);
pd = fitdist(r, 'Normal');
pdr = pdf(pd, x);
% See the fit
figure
histogram(r,'Normalization','pdf');
hold on; grid on;
plot(x,pdr,'LineWidth',2)
Thanks for your response!
My pleasure!
In my code, none of the graphics are visible. A slightly different version is:
r = normrnd(10,1,100,1); % Create Data
figure
set(gcf,'Visible','off')
h = histfit(r,6);
CurveX = h(2).XData;
CurveY = h(2).YData;
I thought of using fitdist and pdf, however since histfit is what you specified, does everything in one call, and you didn’t mention wanting the parameters, I decided to go with that.
Otis
Otis el 26 de Ag. de 2020
I did not know about fitdist when I asked my question. I came across that later, but before I saw your first response. As it turns out, I did want to plot the fit, so using histfit and grabbing the data like you show above would've done what I wanted!! Anyway, I now know two solutions, and there's nothing wrong with that!!
Thanks again!!
Star Strider
Star Strider el 26 de Ag. de 2020
As always, my pleasure!
Charlotte Han
Charlotte Han el 3 de Mzo. de 2023
Hi,
I am wondeirng if there is a way to only plot the fit but not the histogram, using histfit?
Thanks
@Charlotte Han — There is.
Two options —
figure
hhf = histfit(2*randn(1,100)+1, 25);
Bars = findobj(hhf, 'Type','Bar');
delete(Bars) % Delete 'Bar' Plot
Lines = findobj(hhf, 'Type','Line');
figure
plot(Lines.XData, Lines.YData, '-r', 'LineWidth',2) % Save & Plot 'Line'
.
Charlotte Han
Charlotte Han el 3 de Mzo. de 2023
Much appreciated!
Am I able to have two fits on the same plot but not on top of each other, but side by side like subplots?
Star Strider
Star Strider el 3 de Mzo. de 2023
I am not certain what you want to do. See if the tiledlayout function will work.
A Vote would be appreciated!
.

Iniciar sesión para comentar.

Más respuestas (1)

Babar
Babar el 27 de Mayo de 2022

0 votos

r = normrnd(10,1,100,1); % Create Data
h = histfit(r,6);
set(gcf,'Visible','off')
CurveX = h(2).XData;
CurveY = h(2).YData;

Productos

Etiquetas

Preguntada:

el 26 de Ag. de 2020

Comentada:

el 3 de Mzo. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by