The numerator is a simple sum of terms. As you write it, it is simply
A sum is just a sum is just a sum. In MATLAB, you might write that as
assuming there are n-3 terms in the vector CP. If CP has more terms than that, then the numerator might be simply written as
However, the denominator is NOT what you have written. Expand the sum, and we get...
|P(2) - P(1)| + |P(3) - P(2)| + |P(4) - P(3)| + ...
where stuff is the absolute value of stuff, thus abs(stuff). If the vector of elements represented by P is not sorted by their value, then sometimes P(k) will be greater than P(k-1), sometimes the reverse will be true. In that case, then the absolute value will essentially subtract those terms in the opposite order. Think of it as if the absolute value inserts a minus sign in there when needed.
However, IF it is true that P is sorted in order, then that sum could be compressed down by some amount, but it still matters if some of the elements of P were negative. So I would suggest that you not try to compress that denominator sum. (And no matter what, it would not be what you have written.) Write the denominator as something like this:
sum( abs( P(1:(n-1)) - P(1:(n-2)) ) )
(And, it is indeed true that P(0) simply does not exist in MATLAB. MATLAB uses a 1-based index system.)