I have a matrix A (Mx2), and matrix B (Nx2), with M>=N.
I have to compute the perpendicular euclidean distance to test similarity between A and B. Refering to the image, a single euclidean distance is the segment between each pi and p’i, once computed every single perpendicular distance, I can compute the mean or the sum to get a single parameter. Do you know a matlab routine or such a script that do this?

I have a matrix A (Mx2), and matrix B (Nx2), with M>=N. I have
Share
If you know that p1 .. p4 lie between p0 and p5, then you can use the area of a triangle to calculate the perpendicular distance easily:
The area of a triangle is found by
where
I think you can gain a performance improvement using the dot product for projection and pythagorean theorem:
In either case, if your cost function involves mean-squared error, you can eliminate the
sqrtcall by just evaluating the squared-error instead. Norm-squares are also cheaper to calculate than callingnormand then squaring (use a dot product instead).