comparison m-toolbox/classes/@smodel/fromExpression.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 % FROMEXPRESSION
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % FUNCTION: fromExpression
5 %
6 % DESCRIPTION: Construct an smodel from an expression
7 %
8 % CALL: mdl = fromExpression(a, pl)
9 %
10 % PARAMETER: pl - plist
11 %
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 function mdl = fromExpression(mdl, pli)
14
15 VERSION = '$Id: fromExpression.m,v 1.11 2011/08/17 07:01:32 hewitson Exp $';
16
17 % get smodel info
18 ii = smodel.getInfo('smodel', 'From Expression');
19
20 % Set the method version string in the minfo object
21 ii.setMversion([VERSION '-->' ii.mversion]);
22
23 % Combine input plist with default values
24 pl = applyDefaults(ii.plists, pli);
25
26 % Set fields
27 expr = pl.find('expression');
28 params = pl.find('params');
29 vals = pl.find('values');
30 xvar = pl.find('xvar');
31 xvals = pl.find('xvals');
32
33 % Check the contents of vals
34 if iscell(vals)
35 for ll=1:numel(vals)
36 if isa(vals{ll}, 'ao')
37 vals{ll} = vals{ll}.y;
38 end
39 end
40 else
41 if isa(vals, 'ao')
42 vals = {vals.y};
43 end
44 end
45
46 % Set params and default values
47 if ~isempty(params)
48 mdl.params = params;
49 if ~isempty(vals)
50 mdl.values = vals;
51 end
52 end
53
54 % Set x-variable
55 if ~isempty(xvar)
56 mdl.xvar = xvar;
57 end
58
59 % Set x-values
60 if ~isempty(xvals)
61 if isa(xvals, 'ao')
62 mdl.xvals = xvals.x;
63 else
64 mdl.xvals = xvals;
65 end
66 end
67
68 % Set expression
69 mdl.expr = msym(expr);
70
71 % Add history
72 mdl.addHistory(ii, pl, [], []);
73
74 % Set object properties
75 mdl.setObjectProperties(pl, {'params', 'values', 'xvals', 'xval'});
76
77 end