Many of the plotting functions in MATLAB and toolboxes (thought not all) allow both the following syntaxes:
plotfcn(data1, data2, ...)
plotfcn(axes_handle, data1, data2, ...)
The first plots into the current axes (gca
) or creates and plots into a new axes if none exists. The second plots into the axes with handle axes_handle
.
Having looked into the internals of several MATLAB and toolbox plotting functions, it looks like there isn't really a standardised way that MathWorks do this. Some plotting routines use the internal, but open, function axescheck
to parse the input arguments; some do a simple check on the first input argument; and some use a more complex input-parsing subfunction that can handle a larger variety of input syntaxes.
Note that axescheck
appears to use an undocumented syntax of ishghandle
- the doc says that ishghandle
takes only one input, returning true if it is any Handle Graphics object; but axescheck
calls it as ishghandle(h, 'axes')
, which returns true only if it's specifically an axes object.
Is anyone aware of a best practice or standard for implementing this syntax? If not, which way have you found to be most robust?