Is there a way to use MATLAB's built-in validation functions to compare an argument to an expression or funciton output?
I want to do the following:
function out = myfun(x)arguments x (1,1) double {mustBeGreaterThan(x,pi)}endout = foo;end
Since pi is a function, which is not allowed in the native validation functions, the above code throws an error. Instead I have to define a custom validation function to compare the argument to pi.
function out = myfun(x)arguments x (1,1) double {mustBeGreaterThanPi(x)}endout = foo;endfunction mustBeGreaterThanPi(x)if x <= pi error('Value must be greater than pi.')endend
The validation block cannot pass pi to the custom validation function, so pi must be built into the function. This is a complete pain in the neck if we want to compare, say, ten arguments to ten different irrationals, repeating decimals, or simple expressions; we must define ten custom validation functions, unless we get creative with passing scalars or strings (we could pass c to the validation function where an error is thrown if value <= c*pi, for example).
Best Answer