Try using diff(S,1,dim) to get the difference between sequential elements in the matrix S. Each entry in diff(S) is (x_{n} - x_{n-1}, y_{n} - y_{n-1}, z_{n} - z_{n-1}). Then you can square each element of diff(S): (diff(S)).^2. Finally, sum and take the square root: sqrt(sum(diff(S)).^2),dim). In each of these cases, dim is the dimension along which the operation is to take place. So, for the sake of discussion, let's assume S is nx3 (n columns and 3 rows).
diffS = diff(S,1,1);
squaredDiffS = diff.^2;
output = sqrt(sum(squaredDiffS,2));
The output of this code is (n-1)x1, because one column is lost in the diff command.