Mercurial > hg > ltpda
comparison m-toolbox/classes/@smodel/op.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 % OP Add a operation around the model expression | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: OP Add a operation around the model expression | |
5 % | |
6 % CALL: obj = obj.op('sin'); | |
7 % obj = obj.op(plist('operator', 'sin')); | |
8 % | |
9 % INPUTS: obj - one ltpda model. | |
10 % pl - to set the name with a plist specify only one plist with | |
11 % only one key-word 'operator'. | |
12 % | |
13 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'op')">Parameters Description</a> | |
14 % | |
15 % VERSION: $Id: op.m,v 1.8 2011/04/08 08:56:30 hewitson Exp $ | |
16 % | |
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
18 | |
19 function varargout = op(varargin) | |
20 | |
21 % Check if this is a call for parameters | |
22 if utils.helper.isinfocall(varargin{:}) | |
23 varargout{1} = getInfo(varargin{3}); | |
24 return | |
25 end | |
26 | |
27 % Check if the method was called by another method | |
28 callerIsMethod = utils.helper.callerIsMethod; | |
29 | |
30 if ~callerIsMethod | |
31 %%% Collect input variable names | |
32 in_names = cell(size(varargin)); | |
33 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
34 | |
35 [objs, obj_invars, rest] = utils.helper.collect_objects(varargin(:), '', in_names); | |
36 [pls, invars, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
37 | |
38 %%% Combine plists | |
39 pls = combine(pls, getDefaultPlist()); | |
40 | |
41 % Search for the user input operator | |
42 op = find(pls, 'operator'); | |
43 if ~isempty(rest) | |
44 op = rest{1}; | |
45 pls.pset('operator', op); | |
46 end | |
47 | |
48 if isempty(op) | |
49 error('### Please specify one operator-string, either in a plist or directly.'); | |
50 end | |
51 else | |
52 % Simple call, in the form op(mdls, operator) | |
53 objs = varargin{1}; | |
54 op = varargin{2}; | |
55 end | |
56 | |
57 %%% Set the 'values' | |
58 for ii = 1:numel(objs) | |
59 | |
60 %%% decide whether we modify the input smodel object, or create a new one. | |
61 objs(ii) = copy(objs(ii), nargout); | |
62 | |
63 %%% set the value | |
64 objs(ii).expr.s = [op '(' objs(ii).expr.s ')']; | |
65 if ~callerIsMethod | |
66 objs(ii).name = [op '(' objs(ii).name ')']; | |
67 objs(ii).addHistory(getInfo('None'), pls, obj_invars(ii), objs(ii).hist); | |
68 end | |
69 end | |
70 | |
71 %%% Set output | |
72 if nargout == numel(objs) | |
73 % List of outputs | |
74 for ii = 1:numel(objs) | |
75 varargout{ii} = objs(ii); | |
76 end | |
77 else | |
78 % Single output | |
79 varargout{1} = objs; | |
80 end | |
81 end | |
82 | |
83 %-------------------------------------------------------------------------- | |
84 % Get Info Object | |
85 %-------------------------------------------------------------------------- | |
86 function ii = getInfo(varargin) | |
87 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
88 sets = {}; | |
89 pl = []; | |
90 else | |
91 sets = {'Default'}; | |
92 pl = getDefaultPlist(); | |
93 end | |
94 % Build info object | |
95 ii = minfo(mfilename, 'smodel', 'ltpda', utils.const.categories.helper, '$Id: op.m,v 1.8 2011/04/08 08:56:30 hewitson Exp $', sets, pl); | |
96 end | |
97 | |
98 %-------------------------------------------------------------------------- | |
99 % Get Default Plist | |
100 %-------------------------------------------------------------------------- | |
101 | |
102 function plout = getDefaultPlist() | |
103 persistent pl; | |
104 if ~exist('pl', 'var') || isempty(pl) | |
105 pl = buildplist(); | |
106 end | |
107 plout = pl; | |
108 end | |
109 | |
110 function pl = buildplist() | |
111 | |
112 pl = plist(); | |
113 | |
114 % Operator | |
115 p = param({'Operator', 'The operator to apply.'}, paramValue.EMPTY_STRING); | |
116 pl.append(p); | |
117 end | |
118 |