val=getoptkey(key,default,opt) or val=getoptkey(key,default,'key1',val1,'key2',val2, ...) query the value of a key from a structure or a list of key/value pairs author: Qianqian Fang, <q.fang at neu.edu> input: key: a string name for the target struct field name default: the default value of the key is not found opt: a struct object; the field names will be searched to match the key input, opt can be a list of 'keyname'/value pairs output: val: val=opt.key if found, otherwise val=default -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0001 function val=getoptkey(key,default,varargin) 0002 % 0003 % val=getoptkey(key,default,opt) 0004 % or 0005 % val=getoptkey(key,default,'key1',val1,'key2',val2, ...) 0006 % 0007 % query the value of a key from a structure or a list of key/value pairs 0008 % 0009 % author: Qianqian Fang, <q.fang at neu.edu> 0010 % 0011 % input: 0012 % key: a string name for the target struct field name 0013 % default: the default value of the key is not found 0014 % opt: a struct object; the field names will be searched to match the 0015 % key input, opt can be a list of 'keyname'/value pairs 0016 % 0017 % output: 0018 % val: val=opt.key if found, otherwise val=default 0019 % 0020 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net) 0021 % 0022 0023 val=default; 0024 if(nargin<=2) return; end 0025 opt=varargin2struct(varargin{:}); 0026 if(isstruct(opt) && isfield(opt,key)) 0027 val=getfield(opt,key); 0028 end 0029