Updated 20 Sep 2016
Functions for non-parametrically testing whether two multidimensional samples were drawn from the same parent distribution. One function implements Fasano & Franceschini's generalization  to two dimensions (kstest2d.m) of the Kolmorogov-Smirnov test, while the second implements Aslan & Zech's and Szekely & Rizzo's test based on an analogy to statistical energy [2,3], which is minimized when the two samples are drawn from the same parent distribution (minentest.m). In both cases, the analytic distribution of the statistic is unknown, and approximations are used for statistical testing. For the K-S test, I use an approximation due to Press et al.  that represents a fit to the percentiles that Fasano & Franceschini obtained by Monte Carlo simulation of a simple model. For the energy test, p-values are obtained via permutation of the aggregated samples.
The K-S test currently only works for two-dimensional data, but the minimum energy test accepts n-dimensional inputs (although significance testing may become prohibitively expensive).
Both functions are written as two-sample tests, although modifying the minimum energy test for testing goodness-of-fit is straightforward if it is possible to sample from the distribution one is interested in testing the data against (detailed in reference ).
 Fasano, G, Franceschini, A (1987). A multidimensional version of the Kolmorogov-Smirnov test. Mon Not R Astr Soc, 225:155-70
 Aslan, B, Zech, G (2005). Statistical energy as a tool for binning-free, multivariate goodness-of-fit tests, two sample comparison and unfolding. Nuc Instr and Meth in Phys Res A, 537: 626-36
 Szekely, G, Rizzo, M (2014) Energy statistics: A class of statistics based on distances. J Stat Planning & Inference 143: 1249-1272
 Press et al. (1992). Numerical Recipes in C. Cambridge University Press
Visit https://github.com/brian-lau/multdist for more info.
Brian Lau (2020). 2-d Kolmorogov-Smirnov test, n-d energy test, Hotelling T^2 test (https://www.github.com/brian-lau/multdist), GitHub. Retrieved .
Added Szekely & Rizzo variant to energy test. Added Hotelling T^2 test for comparison.