I have a function where two of the input parameters (a and b) must be within the range . So I have written the following code to check if the input arguments are valid:
if ~(varargin{1} > 0 && varargin{1} < 1), error('Parameters must be in the interval [0,1]')elsea = varargin{1};endif ~(varargin{2} > 0 && varargin{2} < 1), error('Parameters must be in the interval [0,1]')elseb = varargin{2};end
But I am repeating the same process twice, so I am wondering if there is a more compact way to apply the same criterion to both parameters simultaneously. Is there a shorter way to write this code?
Any suggestions would be greatly appreciated.
Best Answer