Will D Tran
Will D Tran

Reputation: 39

How to plot a probability mass function in matlab

I am new to matlab and would like to know how to plot a graph when it states

a =  -1    0   1       2       3
----------------------------------
p(a)1/24  1/2  1/4   1/6     1/24

Any tips on how to do it would be helpful!

Upvotes: 0

Views: 13179

Answers (2)

zelanix
zelanix

Reputation: 3562

Because this shows up high when searching for MATLAB PMF, an alternative way to plot discrete probability distributions is the stem function.

a = [-1 0 1 2 3]; p = [1/24 1/2 1/4 1/6 1/24];
stem(a,p);
set(gca, 'xlim', [-1.5 3.5]);

enter image description here

Upvotes: 1

Stedy
Stedy

Reputation: 7469

For a probability mass function, I would use bar

>> a = [-1 0 1 2 3]; p = [1/24 1/2 1/4 1/6 1/24]; bar(a,p)

enter image description here

Upvotes: 1

Related Questions