refactor to use the builtin ind2sub function, which I just discovered