Converting a Matlab code into Julia

See Finding Position of Element in an Array - #9 by kristoffer.carlsson