Code covered by the BSD License  

Highlights from
Gilson HPLC Pump RS232 communication

Gilson HPLC Pump RS232 communication

by

 

Communicates with Gilson HPLC pumps via RS232 (and 508 interface module)

catstructs(varargin)
function output = catstructs(varargin)
% Concatenate structures.  This also overwrites duplicate fields, so that
% the later arguments take priority over earlier arguments.

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

% removes the empty arguments (they get ignored)
varargin = varargin(~cellfun('isempty', varargin));

% counts the new arguments
numArgs = numel(varargin);

% initialises allStruct
allStruct = 0;

% for each argument checks that they're a structure
for m = 1:numel(varargin)
    % is it a structure?
    allStruct = allStruct + isstruct(varargin{m});
end

% are they all structures?
if allStruct ~= numArgs
    % errors
    error('All arguments must be structures.')
end

% defines the output as the first argument
output = varargin{1};

% for each structure...
for n = 2:numArgs
    % get the fieldnames
    fields = fieldnames(varargin{n});

    % for each field
    for nn = 1:numel(fields)
        % add it on to the first stucture
        output.(fields{nn}) = varargin{n}.(fields{nn});
    end
end

Contact us