I've uploaded a new and improved version. Corrected a bug in the rejection rule, as pointed out in the comments. Now it works as intended. Added an example along with an extensive test and a comparison with the Kolgomorov-Smirnov test provided by Matlab.

You can't use it directly for segmentation. This will only compute a distance map from a set of initial points. You need to read some papers and find out how to use that for segmentation.

This does not seem to work correctly. As a test I ran cmtest2(random('Normal',0,1,1,4000000),random('Normal',0,1,1,4000000)) that's 4 million samples from the same normal distribution and I got a p value of .067.

Which equation in academic reference (1) does the formula for 'CMstatistic' on line 143 refer to? Equation (6) in "On the distribution of the two-sample Cramer-von Mises criterion" looks very different.

This does not seem to work correctly. As a test I ran cmtest2(random('Normal',0,1,1,4000000),random('Normal',0,1,1,4000000)) that's 4 million samples from the same normal distribution and I got a p value of .067.

Which equation in academic reference (1) does the formula for 'CMstatistic' on line 143 refer to? Equation (6) in "On the distribution of the two-sample Cramer-von Mises criterion" looks very different.

Comment only