Interestingly contour does not directly call contourc anywhere, instead it passes its input arguments to a contourgroup constructor, and all the magic happens inside that...
This opens the possibility of one undocumented solution: call the contourgroup constructor directly with "visible" "'off":
h = specgraph.contourgroup('Visible','off', 'LevelList',3, 'XData',pinionSurf.X, 'YData',pinionSurf.Y, 'ZData',pinionSurf.Z, 'RefreshMode','auto');
M = get(h, 'ContourMatrix')
delete(h)
This gives exactly the same output as your contour call, just without the visible graphics (and hence faster). I realize that this still technically involves graphics...
Another undocumented option is to call contours directly:
M = contours(pinionSurf.X, pinionSurf.Y, pinionSurf.Z, [a,a]);
This also returns exactly the same matrix. Note that the contourgroup constructor actually calls contours, which in turn calls contourc with just the Z matrix, and then post-processes the output matrix before returning it as an output argument. Of course I cannot advise you to reverse-engineer MATLAB code... but calling contourc with just the Z matrix is trivial... sadly the post processing is not so trivial, but it is worth taking a look at.
Best Answer