how to get outputs from normal distribution fitdist to display in my plot title using sprintf

4 visualizaciones (últimos 30 días)
trying to use sprintf to plot the values of mu and sigma in my title for my histogram plot. Mu and sigma are the outputs from the pd=fitdist(data,'normal'). Any suggestions appreciated! Thanks!
this is what I have;
histfit(data,20)
pd = fitdist(data,'normal')
xlabel('Energy in eV')
ylabel('Count Rate')

Respuesta aceptada

Image Analyst
Image Analyst el 13 de Feb. de 2023
Editada: Image Analyst el 13 de Feb. de 2023
Try this:
data = randn(5000, 1);
histfit(data,20)
pd = fitdist(data,'normal')
pd =
NormalDistribution Normal distribution mu = 0.0209271 [-0.00653814, 0.0483923] sigma = 0.990638 [0.971596, 1.01045]
fontSize = 18;
grid on;
caption = sprintf('Mu = %f. Sigma = %f', pd.mu, pd.sigma);
title(caption, 'FontSize', fontSize)
xlabel('Energy in eV', 'FontSize', fontSize)
ylabel('Count Rate', 'FontSize', fontSize)
  5 comentarios
Image Analyst
Image Analyst el 13 de Feb. de 2023
You forgot to attach 'data01.txt' so I can't run your code.
Line 9 is
title('X-ray detection events')
and would not throw that error because nothing is being indexed, unless you have called some variable "title" in some other script and it's still hanging around in the base workspace. Try calling
clear all
as the first line of your script to get rid of any prior variables you don't need.
Kay
Kay el 13 de Feb. de 2023
Oh sorry about that! I think i figured it out, I restarted my computer and that seemed to help. I'll remember the clear all for next time. I think I need to do some updates to my computer, matlab has been glitchy for a few days. Thanks again for your help!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Identification 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