Mercurial > hg > ltpda
comparison m-toolbox/classes/@param/setDefaultOption.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % SETDEFAULTOPTION Sets the default option of the a param object. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: SETDEFAULTOPTION Sets the default option of the a param | |
5 % object. If the option doesn't exist in the options of the | |
6 % param object then this method throws an error. | |
7 % | |
8 % CALL: obj = obj.setDefaultOption(option); | |
9 % | |
10 % INPUTS: obj - A single param object | |
11 % option - An option which should to be set. | |
12 % | |
13 % VERSION: $Id: setDefaultOption.m,v 1.7 2011/04/22 21:14:57 mauro Exp $ | |
14 % | |
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
16 | |
17 function p = setDefaultOption(p, option) | |
18 | |
19 % Check input | |
20 if numel(p) ~= 1 | |
21 error('### This method works only with one input parameter object.'); | |
22 end | |
23 if ~ischar(option) && isa(option, 'paramValue') && numel(option) ~= 1 | |
24 error('### This method works only with one input option.'); | |
25 end | |
26 | |
27 if ~isa(p.val, 'paramValue') | |
28 p.val = option; | |
29 return; | |
30 end | |
31 | |
32 % Make a copy if the user doesn't use the modifier command | |
33 p = copy(p, nargout); | |
34 | |
35 found = false; | |
36 for ii = 1:numel(p.val.options) | |
37 | |
38 % Use different compare methods for the different types of 'option' | |
39 switch class(option) | |
40 case 'char' | |
41 | |
42 % CHAR | |
43 if strcmpi(p.val.options{ii}, option) | |
44 p.val.setValIndex(ii); | |
45 found = true; | |
46 break; | |
47 end | |
48 | |
49 case 'specwin' | |
50 | |
51 % SPECWIN | |
52 if strcmpi(p.val.options{ii}, option.type) | |
53 p.val.setValIndex(ii); | |
54 found = true; | |
55 break; | |
56 end | |
57 | |
58 case 'paramValue' | |
59 if isequal(p.val.options{ii}, option.options{option.valIndex}) | |
60 p.val.setValIndex(ii); | |
61 found = true; | |
62 break; | |
63 end | |
64 | |
65 otherwise | |
66 | |
67 % ALL OTHER TYPES | |
68 if isequal(p.val.options{ii}, option) | |
69 p.val.setValIndex(ii); | |
70 found = true; | |
71 break; | |
72 end | |
73 | |
74 end | |
75 end | |
76 | |
77 if ~found | |
78 % IF the selection mode of the param-object is OPTIONAL then append | |
79 % this new option to the param.options | |
80 if (p.val.selection == paramValue.OPTIONAL) | |
81 newOptions = [reshape(p.val.options, [], 1); {option}]; | |
82 p.val.setValIndexAndOptions(numel(newOptions), newOptions); | |
83 else | |
84 % throw an error if the option is not found in the param-options | |
85 error('### I couldn''t find the option [%s] in the param-options.', utils.helper.val2str(option)); | |
86 end | |
87 end | |
88 | |
89 end | |
90 |