Note that this has questionable results in the case where an X is exactly equal to a Y: it will return the bin number of thenext Y. You could, though, correct for this with
t = (X == Y(tIND));
IND(t) = IND(t) - 1;
It is also possible to correct for it at the time of histc(), but the code becomes notably more difficult to read.
Best Answer