Actually, it DOES use the proper formula. The formula divides by delta. (I used delta here, because otherwise you have h in two places, used for two different purposes.)
delta = h(3:n) - h(1:n-2)
See that delta is computed as a difference that is twice the stride between consecutive points, at least if they are equally spaced.
If the points were not equally spaced, then the formula divides by an appropriate value, although it will no longer be second order as an approximation for the derivative.
Look carefully at the code. It is indeed correct.