Complete j2c method to correctly mirror functionality of matlab function.