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.

structrep(input, match, replace)
function input = structrep(input, match, replace)
% STRUCTREP replaces matching elements with the specified replacement (it can
% be anything at all) (this is a flat replacement)

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

% error checking
if ~isstruct(input)
    % the input must be a structure
    error('This function only works on structure.')
end

% gets the field names
fieldNames = fieldnames(input);

% for each part of the structure
for m = 1:numel(input)
    % for each field name
    for mm = 1:numel(fieldNames)
        % if it matches, replace it
        if isequal(input{m}.(fieldNames{mm}), match)
            % replaces it
            input{m}.(fieldNames{mm}) = replace;
        end
    end
end

Contact us