I usually use a template that is also used by many of the build functions that are part of MATLAB:
function varargout = myplot(obj, varargin) % Check the number of output arguments. nargoutchk(0,1); % Parse possible axes input. [ax, args, ~] = axescheck(varargin{:}); %
axescheck is an undocumented function. You always take a small risk when doing this, but it is present and unchanged in MATLAB forever, and it is used by many very stable build functions in MATLAB, so you should be fine.
What he does is check to see if the first argument is an axis descriptor. If so, then ax is the handle, and args are the rest of the input arguments. If not, ax empty, and args contains all the input arguments.
Hope this helps!
Edit: more information about axescheck on request.
First, you can see the location and source code for axescheck by typing which axescheck and edit axescheck . That way you can see exactly what he is doing.
Syntax [AX, ARGS, NARGS] = AXESCHECK(ARG1, ARG2, ...) .
First, it checks if ARG1 an axis descriptor. If so, it returns as ax , the remaining arguments ( ARG2, ... ) are returned in args , and NARGS is the value of nargin minus 1.
Secondly, it checks whether any of the input arguments is a pair of parameters and values ββwith the Parent parameter. If so, then all pairs of the pair of parameters and the Parent parameter are removed from the list. The specified axis is returned in ax , the remaining arguments are returned in args , and NARGS is the nargin value minus the number of arguments removed.
If none of the axes is indicated by any of the indicated methods, then ax empty, args are only input arguments, and NARGS is the nargin value.
axescheck works with both old-style double handles (Handle Graphics 1) and new-style descriptors (Handle Graphics 2) of the matlab.graphics.axis.Axes class.
It also checks to see if the supplied descriptor is the descriptor of the remote object, causing an error, if any.
It is quite widely used in many built-in functions of MATLAB construction - see, for example, hist.m, polar.m, surfl.m, bar3.m, comet.m, pie.m and many others.