function y=key(name,default,varargin)
%KEY   Extract one key value from a list of key options with unknown length.
%
%   y = KEY(name,default,'KeyName','KeyValue',...) compares the 'KeyName's
%   with 'name' and returns the following 'KeyValue'.  If no 'KeyName' matching
%   'name' is found, 'default' is returned.
%
%   name      Name of the argument to retrieve the value of.
%   default   Default argument value.
%   y         Argument value.
%
%   See also VARARGIN.

% Copyright (c) Mattias Schevenels 2003-2014

y=default;
for iarg=1:nargin-3
    if strcmpi(name,varargin{iarg})
        y=varargin{iarg+1};
        break;
    end
end