D = pdist2(X,Y) returns a matrix D containing the Euclidean distances between each pair of observations in the mx-by-n data matrix X and my-by-n data matrix Y. Rows of X and Y correspond to observations, columns correspond to variables. D is an mx-by-my matrix, with the (i,j) entry equal to distance between observation i in X and observation j in Y. The (i,j) entry will be NaN if observation i in X or observation j in Ycontain NaNs.
You can calculate the empirical probability density functions of your histograms in MATLAB. The result will be the functions p(x) and q(x), which you can plug into your numerical integral.