annotate general/prefs.m @ 61:eff6bddf82e3
tip
Finally implemented perceptual brightness thing.
author |
samer |
date |
Sun, 11 Oct 2015 10:20:42 +0100 |
parents |
e44f49929e56 |
children |
|
rev |
line source |
samer@4
|
1 function P=prefs(varargin)
|
samer@4
|
2 % prefs - manage name-value map as a structure
|
samer@4
|
3 % Values can be retreived with defaults using GETPARAM
|
samer@4
|
4 %
|
samer@4
|
5 % Arguments can be name value pairs, eg
|
samer@4
|
6 % opts=prefs('foo',5,'bar',7)
|
samer@4
|
7 % opts.foo=4
|
samer@4
|
8 % opts.bar=7
|
samer@4
|
9 %
|
samer@4
|
10 % Or structures
|
samer@4
|
11 % opts=prefs(defopts,'foo',5)
|
samer@4
|
12 %
|
samer@4
|
13 % Later arguments override earlier ones. A typical usage is
|
samer@4
|
14 % with variable argument lists and GETPARAM, eg
|
samer@4
|
15 %
|
samer@4
|
16 % function somefun(a,b,varargin)
|
samer@4
|
17 % ...
|
samer@4
|
18 % opts=prefs('foo',5,varargin{:});
|
samer@4
|
19 % fooness=opts.foo;
|
samer@4
|
20 % barness=getparam(opts,'bar',12);
|
samer@4
|
21 %
|
samer@4
|
22 % See also: GETPARAM, GETFIELD, ISFIELD
|
samer@4
|
23
|
samer@4
|
24 P=struct;
|
samer@4
|
25 n=1;
|
samer@4
|
26 while n<=length(varargin)
|
samer@4
|
27 arg=varargin{n};
|
samer@4
|
28 if isstruct(arg)
|
samer@4
|
29 P=cpfields(fieldnames(arg),arg,P);
|
samer@4
|
30 elseif iscell(arg)
|
samer@4
|
31 pairs=arg;
|
samer@4
|
32 for k=1:length(pairs)
|
samer@4
|
33 P=setfield(P,pairs{k}{1},pairs{k}{2});
|
samer@4
|
34 end
|
samer@4
|
35 else
|
samer@4
|
36 P=setfield(P,varargin{n},varargin{n+1});
|
samer@4
|
37 n=n+1;
|
samer@4
|
38 end
|
samer@4
|
39 n=n+1;
|
samer@4
|
40 end
|
samer@4
|
41
|