% get an options structure from varargin, search for fields
options=[];
foo=0;
bar = 'hello world';

if ~isempty(varargin)
    options=varargin{1};
    if isfield(options, 'foo')
        foo=options.foo;
    else
        foo=0;
    end
    if isfield(options, 'bar')
        bar=options.bar;
    end
end