MATLAB Answers

How to make gaussian pplot with my data

2 views (last 30 days)
Stefano Vigna
Stefano Vigna on 11 Dec 2019
Answered: SaiDileep Kola on 29 Jan 2020
Hi, I have a question and I don't understending how to do something and which function I need to solve the problem.
I have external data from two vector in excel and I need to produce two plot like a gaussian graph with them.
I used xlsread to put the data in matlab and histfit for plot the probability density function plot with histogram :
[num,txt,raw] = xlsread('Gaussian.csv');
x1 = num(:, 1);
x2 = num(:, 2);
G1 = histfit(x1);
But I need the probability density function without the histogram and I don't understand how histfit interpolate automatically the data, I tried to use pdf function but I want that the mu be in the average of my data for x-axis and I don't need to modify sigma. I don't understand how to use interp1 for my data to create the gaussian plot e how to overlap the second gaussian plot with the first one.
thank you for the answer.

Answers (1)

SaiDileep Kola
SaiDileep Kola on 29 Jan 2020
As per my understanding you want to plot the probability density function with “mu” which must be average of your data. You can do this with the help of “mean” function. You can create gaussian pdf for your data and see how they overlap by setting the distribution name as “Normal”. Here is a sample code:
x1 = [-2 -1 0 1 2];
pd = makedist('Normal','mu',mu,'sigma',sigma);
y = pdf(pd,x1);
hold on
x2 =(-9:5);
pd = makedist('Normal','mu',mu,'sigma',sigma);
y = pdf(pd,x2);

Community Treasure Hunt

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

Start Hunting!

Translated by