gabboshow
gabboshow

Reputation: 5569

how to fit a bi-modal distribution to a function matlab

I have a vector named speed containining the speed of 200 walks

speed = [normrnd(80,2,100,1); normrnd(120,10,100,1)];

This vector follows a bimodal distribution.

steps is another vector contaning the number of steps for each walk:

a = 8;
b = 100;
steps = (b-a).*rand(200,1) + a;

I create the histgram plot of the steps performed in function of the speed:

binstep = 1.5;
binranges = (min(speed):binstep:max(speed)+binstep)';
[~, ind] = histc(speed, binranges);
bincounts = accumarray(ind, steps, size(binranges));
hFig = figure(); axh = axes('Parent', hFig); hold(axh, 'all'); grid(axh, 'on');
bar(axh, binranges, bincounts); axis(axh, 'tight');

Now I would like to

  1. fit a bi-modal distribution to the barplot,
  2. estimate the parameters of the bi-modal distribution u1,u2,sigma1,sigma2,
  3. assess whether it is a good fit or not (i.e. the distribution is bi modal).

Could you please help me?

Upvotes: 0

Views: 930

Answers (1)

kiril
kiril

Reputation: 5212

To fit data to distributions just use the fitdist function. In your case, with a Normal it would be:

pd = fitdist(y,'Normal')

Upvotes: 0

Related Questions