This obviously refers to FEX #20922. Assuming that the data is gridded, such as could be given to surf(), then:
[x y z] = sphere(21);
stlWrite('thing.stl',x,y,z,'triangulation','f')
By default, when given xyz data, the triangulation method is 'delaunay', which only works for data which is single-valued in x,y (e.g. a surface relief). If given something like this sphere, it will fail.
If you just have an unstructured list of xyz points (a point cloud), then that's a different story.