Given a pair of two variables (X,Y), how can you generate and plot the empirical joint PDF and CDF in vanilla MATLAB (no toolboxes)?
Generate and plot the empirical joint pdf and CDF
16.6k views Asked by Elpezmuerto At
1
Given a pair of two variables (X,Y), how can you generate and plot the empirical joint PDF and CDF in vanilla MATLAB (no toolboxes)?
Original answer (Matlab R2015a or lower)
The data are:
X
,Y
.x_axis
,y_axis
. The edges must obviously be increasing, but need not be uniformly spaced.The resulting PDF and CDF are defined at the centers of the rectangles determined by the x and y edges.
To plot the results in 3D, use
surf(...)
instead ofimagesc(...)
.Edited answer (Matlab R2015b or higher)
Matlab R2015b includes an
histogram2
function that does all the work. It automatically does the normalization to obtain the PDF (given the appropriate input flag), or even the CDF.Using the same example as above,