Mercurial > hg > ltpda
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/@smodel/fromExpression.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,77 @@ +% FROMEXPRESSION +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% FUNCTION: fromExpression +% +% DESCRIPTION: Construct an smodel from an expression +% +% CALL: mdl = fromExpression(a, pl) +% +% PARAMETER: pl - plist +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function mdl = fromExpression(mdl, pli) + + VERSION = '$Id: fromExpression.m,v 1.11 2011/08/17 07:01:32 hewitson Exp $'; + + % get smodel info + ii = smodel.getInfo('smodel', 'From Expression'); + + % Set the method version string in the minfo object + ii.setMversion([VERSION '-->' ii.mversion]); + + % Combine input plist with default values + pl = applyDefaults(ii.plists, pli); + + % Set fields + expr = pl.find('expression'); + params = pl.find('params'); + vals = pl.find('values'); + xvar = pl.find('xvar'); + xvals = pl.find('xvals'); + + % Check the contents of vals + if iscell(vals) + for ll=1:numel(vals) + if isa(vals{ll}, 'ao') + vals{ll} = vals{ll}.y; + end + end + else + if isa(vals, 'ao') + vals = {vals.y}; + end + end + + % Set params and default values + if ~isempty(params) + mdl.params = params; + if ~isempty(vals) + mdl.values = vals; + end + end + + % Set x-variable + if ~isempty(xvar) + mdl.xvar = xvar; + end + + % Set x-values + if ~isempty(xvals) + if isa(xvals, 'ao') + mdl.xvals = xvals.x; + else + mdl.xvals = xvals; + end + end + + % Set expression + mdl.expr = msym(expr); + + % Add history + mdl.addHistory(ii, pl, [], []); + + % Set object properties + mdl.setObjectProperties(pl, {'params', 'values', 'xvals', 'xval'}); + +end