Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation

by

 

06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

isnumberbetween(number, minimum, maximum)
function response = isnumberbetween(number, minimum, maximum)
% ISNUMBERBETWEEN checks if its a number between some values. the maximum
% and the minimum can be omitted if necessary.

% checks the number of arguments
error(nargchk(1, 3, nargin))

% checks the number
if nargin >= 1 && ~iscell(number) && (isempty(number) || ~isnumeric(number))
    % errors
    error('Not a valid number to compare.')
end

% if the minimum was supplied
if nargin >= 2 && (isempty(minimum) || ~isnumeric(minimum) || ~isreal(minimum) || isnan(minimum))
    % errors
    error('Not a valid minimum number to compare against.')
end

% if the maximum was supplied
if nargin >= 3 && (isempty(maximum) || ~isnumeric(maximum) || ~isreal(maximum) || isnan(maximum))
    % errors
    error('Not a valid maximum number to compare against.')
    
else
    % set it to be infinite
    maximum = Inf;
end

% if the number is a cell array, recursively call this function
if iscell(number)
    % tries it
    response = cellfun((@(x) isnumberbetween(x, minimum, maximum)), number, 'UniformOutput', false);
    
else
    % returns a logical value
    response = all(~isnan(number)) && isreal(number);

    % if it meets those criteria...
    if response
        % compares it again
        response = number >= minimum & number <= maximum;

    else
        % returns a response the same size of the input
        response = false(size(number));
    end
end

Contact us