I think ballardw mailed it: The MAD function will return 0 when more than half of the values are the same value.
In addition, I'd like to point out that the outarray_M matrix is not necessary in your code. Hopefully, that code is left over from a more complicated example (thanks for supplying a short module for us to view!). If not, you can use
if unit ^= 0 then...
... View more