Biometric matching score calculator
Regarding the vectorized code:


permute can be considered a "Zero-cost operation".
Logical operations are performed fastest using bsxfun.
Arithmetic operations are fastest using bsxfun.


Therefore, it's close to impossible to improve the performance of the vectorized code you've posted.



Now, the question is: Is it correct?

It's hard to tell without knowing the exact data, but just by reading the code and your comments, I would think it is.

The reason why I think it is correct, even though the if conditions didn't return the same result:

You're comparing floating point values using ==. Check out Is floating point math broken?

When checking for equality, you should always use some tolerance. Have a look at the example below, where we are comparing 0.3 with 0.1 + 0.2:

x = 0.1;
y = 0.2;
z = 0.3;
the_same = (z == (x + y))
the_same =
     0
the_same = abs(z - (x + y)) &lt; eps
the_same =
     1