Update carve.m

Made it slightly faster, by reducing the number of operations in the loop and the number of variables.