How can I use fitdist function

Hello,
I tried to use the function fitdist. The only result is an error:
Undefined function 'fitdist' for input arguments of type 'double'.
Error in FitaNormalDistributiontoDataExample (line 13) pd = fitdist(x,'Normal')
This was the result of running the code from help file: C:\Users\...\Documents\MATLAB\Examples\FitaNormalDistributiontoDataExample\FitaNormalDistributiontoDataExample.m
%%Fit a Normal Distribution to Data
% Copyright 2015 The MathWorks, Inc.
Load the sample data. Create a vector containing the patients' weight data.
load hospital
x = hospital.Weight;
Create a normal distribution object by fitting it to the data.
pd = fitdist(x,'Normal')
Plot the pdf of the distribution.
x_values = 50:1:250;
y = pdf(pd,x_values);
plot(x_values,y,'LineWidth',2)
What is wrong here?

Respuestas (1)

Jaimin
Jaimin el 28 de En. de 2025

0 votos

The error message you are encountering suggests that MATLAB does not recognize the “fitdist” function. This could be due to a few reasons:
  • The “fitdist” function is part of the Statistics and Machine Learning Toolbox. Make sure that this toolbox is installed and licensed on your MATLAB environment.
  • Ensure that your MATLAB path is set correctly and that you are using a version of MATLAB that supports the “fitdist” function.
  • It is possible that another function or script named “fitdist” is shadowing the built-in function. Check your current directory and the MATLAB path for any files named “fitdist.m”.
Here's how you can troubleshoot and resolve the issue:
  • Go to the MATLAB “Command Window” and type “ver”. This will list all installed toolboxes. Look for "Statistics and Machine Learning Toolbox" in the list.
  • Use the which command to check if the function is recognized: “which fitdist”.
For more information kindly refer following MathWorks documentation.
I hope this will be helpful.

Productos

Etiquetas

Preguntada:

el 6 de Mzo. de 2018

Comentada:

el 30 de En. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by