I tend to validate most of my function inputs and often write classes that involve plotting something (either on a supplied axes or creating one if the supplied axes is empty) or adding a UI component to a parent, but I tend to take each case as it comes. e.g.
validateattributes( hParent, { 'matlab.ui.container.internal.UIContainer', 'matlab.ui.Figure' }, { 'scalar' } )
is what I am currently using to test the handle of a parent object that I am going to attach e.g. a uiccontrol or a uipanel to.
try
validateattributes( hAxes, { 'matlab.graphics.axis.Axes' }, { 'scalar' } )
if ~ishghandle( hAxes )
error( 'hAxes must be a valid axes handle' )
end
catch e
throwAsCaller(e);
end
is what I use for validating an axes handle that I want to plot something on, etc etc. So I'm not convinced a 'one size fits all' validation of anything and everything makes too much sense.
It's also useful to note that if you ever want to know the class type to test for you can just create one of the elements in question and class class on it.
e.g.
figure; hAxes = gca;
class( hAxes );
and then just paste the answer into the validateattributes call.
Best Answer