Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 9/Programming Assignment - 8/ex8/lib/jsonlab/jsonopt.m
626 views
1
function 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
26
val=default;
27
if(nargin<=2) return; end
28
opt=varargin{1};
29
if(isstruct(opt) && isfield(opt,key))
30
val=getfield(opt,key);
31
end
32
33
34