Code covered by the BSD License  

Highlights from
Toolbox Sparse Optmization

from Toolbox Sparse Optmization by Gabriel Peyre
Optimization codes for sparsity related signal processing

getoptions(options, name, v, mendatory)
function v = getoptions(options, name, v, mendatory)

% getoptions - retrieve options parameter
%
%   v = getoptions(options, 'entry', v0, mendatory);
% is equivalent to the code:
%   if isfield(options, 'entry')
%       v = options.entry;
%   else
%       v = v0;
%   end
%
%   Copyright (c) 2007 Gabriel Peyre

if nargin<3
    error('Not enough arguments.');
end
if nargin<4
    mendatory = 0;
end

if isfield(options, name)
    v = eval(['options.' name ';']);
elseif mendatory
    error(['You have to provide options.' name '.']);
end 

Contact us at files@mathworks.com