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.

uicontrolcmp(uicontrol1, uicontrol2)
function [commonProperties, differentProperties] = uicontrolcmp(uicontrol1, uicontrol2)
% UICONTROLCMP compares two uicontrols of the same type, and displays the
% properties which do not match.

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

% pairs them together (as a cell array to avoid concatenation issues)
allControls = {uicontrol1; uicontrol2};

% for each uicontrol
for m = 1:numel(allControls)
    % checks it
    if ~isscalar(allControls{m}) || ~ishandle(allControls{m})
        % errors
        error('One of the input argments is not a scalar handle object.')

% changes the all controls thing into a normal matrix
allControls = cell2mat(allControls);

% checks that the types are the same
allTypes = get(allControls, 'Type');

% checks them
if any(~strcmp(allTypes{1}, allTypes))
    % errors
    error('One or more of the uicontrols is not of the same type.')

% gets all the properties
allProperties = get(allControls);

% and the fields
fields = fieldnames(allProperties);

% pre-defines the answer
matching = false(numel(fields), 1);

% saves it
differentProperties = cell(0, 1);
commonProperties = differentProperties;

% for each field (structfun only works on scalar structures ffs)
for n = 1:numel(fields)
    % are they all the same?
    matching(n) = isequal(allProperties(1).(fields{n}), {allProperties(2:end).(fields{n})});
    % saves that properties
    if matching(n)
        % save it
        commonProperties = [commonProperties, fields(n)];
        % its different
        differentProperties = [differentProperties, fields(n)];

Contact us