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.

iscomport(input)
function response = iscomport(input)
% ISCOMPORT checks if a number is a valid COM port number (1-255) or a COM
% port string (COMx where x is a number from 1-255).

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

% depends on the input type
if isempty(input)
    % short-circuit
    response = false;
    
elseif isnumeric(input) || islogical(input)
    % checks it is an integer from 1 to 255
    response = input == uint8(input) & input;
    
elseif ischar(input)
    % checks the string
    response = size(input, 2) >= 4 && strcmp(input(1:3), 'COM') && iscomport(str2double(input(4:end)));
    
elseif iscell(input)
    % recursively calls this function
    response = cellfun(@iscomport, input);

else
    % errors
    error('Input must be either a string, a number, or a cell array (can be a mixture of either).')
end
    
   

Contact us