The gradient by definition is a vector formed by three directional derivatives, `∂F/∂x`, `∂F/∂y` and `∂F/∂z`, so if you only need the `z` component, at least we have two perspectives, which are, in order of recommendation:

1.- You can calculate it directly with diff(F,z). Check the docs https://www.mathworks.com/help/symbolic/differentiation.html

2.- Or you can calculate the directional derivative in the `z` direction using fndir(F,Vz), where Vz is a vector in the desired direction, z in this case. Check the docs https://www.mathworks.com/help/curvefit/fndir.html

This perspectives have the advantage of being based on built in, optimized functions.