Introduction to MATLAB
---------Learning by using it
Elec2600 Tutorial 5
Matlab Windows
Elec2600 Tutorial 5
Definition of Variables, Vectors and Matrices
Elec2600 Tutorial 5
Arithmetic Operators
Elec2600 Tutorial 5
Matrix and Array Operations
Elec2600 Tutorial 5
Control Flow
Elec2600 Tutorial 5
2-D graphics
Help Plot
Other function ?
Elec2600 Tutorial 5 7
Script File
Elec2600 Tutorial 5
Matlab Windows
Elec2600 Tutorial 5
MATLAB Functions for Plotting PMFs
disttool; % interactive demo % sample script % parameters of probability distribution n = 15; p = 0.5; xmin = 0; % minimum limit of plot xmax = 20; % maximum limit of plot x = xmin:xmax; % x values y = binopdf(x,n,p); % values of the binomial pmf plot(x,y,'x'); % generate plot
% y y y
other pmfs = geopdf(x,p); = poisspdf(x,a); = unidpdf(x,n);
% geometric RV, X starts from 1 not 0 % Poisson RV % discrete uniform on {1,...,n}
Elec2600 Tutorial 5
10
Screen shot of disttool application:
MATLAB Functions for Plotting PMFs
Elec2600 Tutorial 5
11
MATLAB: Generating Samples
randtool; % interactive demo % sample script % parameters of probability distribution n = 15; p = 0.5; mm = 1; % size of array of samples (Rows) nn = 500; % size of array of samples (Columns) y = binornd(n,p,mm,nn); % generate samples plot(y,'x'); % generate plot axis([0 500 0 15]);
% y y y
other pmfs = geornd(p,mm,nn); = poissrnd(a,mm,nn); = unidrnd(n,mm,nn);
% geometric RV, X starts from 1 not 0 % poisson RV % discrete uniform on {1,...,n}
12
Elec2600 Tutorial 5
Screen shot of randtool application:
MATLAB Functions for Plotting PMFs
Elec2600 Tutorial 5
13