Edit: used ind2sub() vs. using mod()