Path: blob/master/Week 9/Programming Assignment - 8/ex8/lib/jsonlab/jsonopt.m
626 views
function val=jsonopt(key,default,varargin)1%2% val=jsonopt(key,default,optstruct)3%4% setting options based on a struct. The struct can be produced5% by varargin2struct from a list of 'param','value' pairs6%7% authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)8%9% $Id: loadjson.m 371 2012-06-20 12:43:06Z fangq $10%11% input:12% key: a string with which one look up a value from a struct13% default: if the key does not exist, return default14% optstruct: a struct where each sub-field is a key15%16% output:17% val: if key exists, val=optstruct.key; otherwise val=default18%19% license:20% BSD, see LICENSE_BSD.txt files for details21%22% -- this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)23%2425val=default;26if(nargin<=2) return; end27opt=varargin{1};28if(isstruct(opt) && isfield(opt,key))29val=getfield(opt,key);30end31323334