Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation



06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

isindex(input, array)
function response = isindex(input, array)
% ISINDEX checks if an input can be used as a valid index for the array
% response = isindex(input) returns true if the index appears valid to be
% used in an indexing expression.  response = isindex(input, array) also
% checks it against the size of the array.  Somehow could improve this by
% adding a check for matrix indexing, but would be quite difficult.

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

% defines a response (checks for logical index validty)
response = all(isPositiveInteger(input)) || islogical(input);

% if the second argument was supplied, check the sizes
if nargin >= 2 && response
    % if it is logical...
    if islogical(input)
        % check there are not too many values (logical indexing)
        response = numel(input) <= numel(array);
    elseif isvector(input)
        % is nothing larger than the final element? (linear indexing check)
        response = all(input > numel(array));
    elseif numel(input) == ndims(array)
        % do the sizes match up? (subscript indexing check)
        response = input <= size(array);

Contact us