How to fit data in a normal distribution

11 visualizaciones (últimos 30 días)
Remember Samu
Remember Samu el 22 de Jun. de 2021
Respondida: Aastha el 12 de Jun. de 2025
Hi All,
I have a the attached data and I am trying to plot a the data and fit it into a normal distribution but it looks like the output is not coming out as i expect. The values on the X and the Y axes are not from my data set. Can someone please help fix this. I have attached the code, dataset and the output im getting.
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 7);
%
%% Specify range and delimiter
opts.DataLines = [16, Inf];
opts.Delimiter = "\t";
%
%% Specify column names and types
opts.VariableNames = ["VarName1", "VarName2", "VarName3", "VarName4", "VarName5", "VarName6", "VarName7"];
opts.VariableTypes = ["datetime", "datetime", "double", "double", "double", "double", "double"];
%
%% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
%
%% Specify variable properties
opts = setvaropts(opts, "VarName1", "InputFormat", "dd/MM/yyyy");%dd-MMMM-yyyy HH:mm:ss
opts = setvaropts(opts, "VarName2", "InputFormat", "HH:mm:ss");
%% Import the data
DATA = readtable("E:\Data\2020\B220_DT80\weekly\Jan to May 2021\01Jan2021_8Jan2021.txt", opts);
%% Select the data for processing
D1 = DATA.VarName4;
% D2 = DATA.VarName4;
%% Histogram analysis
DL=8640;
Day1 = D1(1:DL);
...
figure(1)
histfit(Day1)
...
  2 comentarios
Joel Lynch
Joel Lynch el 22 de Jun. de 2021
The figure you attached is your data, but it isn't normally distributed. I produced the following plots, showing histogram() and histfit() of all variables in your data set. As you can see, a guassian fit is going to be poorly fit to this data.
Now if you look at the same with plots over time, you do have periodic data. Is that what you're tring to fit?
Remember Samu
Remember Samu el 22 de Jun. de 2021
Editada: Remember Samu el 22 de Jun. de 2021
Hi Joel,
Thank you so much. Yes that is correct, I am trying to fit, VarName4 and VarName3.

Iniciar sesión para comentar.

Respuestas (1)

Aastha
Aastha el 12 de Jun. de 2025
I understand that you are trying to fit a normal distribution to the variables "VarName4" and "VarName3". However, based on the histograms for both variables, it appears that they are not unimodally distributed and instead exhibit multiple peaks or modes. As a result, fitting a single normal distribution leads to a poor representation of the data.
To address this, you can use the "fitgmdist" function to fit a Gaussian mixture model to your data. A Gaussian mixture model is essentially a weighted combination of multiple Gaussian distributions, which allows it to more accurately model data with multiple modes.
For more details on the "fitgmdist" function, you can refer to the MathWorks documentation here:
I hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by