Fixed ind2sub function to make it usable.