addRequired(p,'num',@checknum);
parse(p,num);
function TF = checknum(x)
TF = false;
if ~isscalar(x)
error('Input is not scalar');
elseif ~isnumeric(x)
error('Input is not numeric');
elseif (x <= 0)
error('Input must be > 0');
else
TF = true;
end
Call the function with an invalid input:
usenum(-1)
Error using usenum (line 4)
The value of 'num' is invalid. Input must be > 0
See Also
inputParser | is* | validateattributes
Related Examples
- “Parse Function Inputs” on page 21-17
- “Create Function Handle” on page 13-2
More About
- “Anonymous Functions” on page 20-24
21 Function Arguments