1function val=jsonopt(key,default,varargin) 2% 3% val=jsonopt(key,default,optstruct) 4% 5% setting options based on a struct. The struct can be produced 6% by varargin2struct from a list of 'param','value' pairs 7% 8% authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) 9% 10% $Id: loadjson.m 371 2012-06-20 12:43:06Z fangq $ 11% 12% input: 13% key: a string with which one look up a value from a struct 14% default: if the key does not exist, return default 15% optstruct: a struct where each sub-field is a key 16% 17% output: 18% val: if key exists, val=optstruct.key; otherwise val=default 19% 20% license: 21% BSD, see LICENSE_BSD.txt files for details 22% 23% -- this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab) 24% 25 26val=default; 27if(nargin<=2) return; end 28opt=varargin{1}; 29if(isstruct(opt) && isfield(opt,key)) 30 val=getfield(opt,key); 31end 32 33 34