view m-toolbox/classes/@ao/fromFcn.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 source

% FROMFCN Construct an ao from a function string
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FUNCTION:    fromFcn
%
% DESCRIPTION: Construct an ao from a function string
%
% CALL:        a = fromFcn(a, pl)
%
% PARAMETER:   pl: Parameter list object
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function a = fromFcn(a, pli)
  
  VERSION = '$Id: fromFcn.m,v 1.22 2011/08/17 07:01:45 hewitson Exp $';
  % get AO info
  ii = ao.getInfo('ao', 'From Function');
  
  % Set the method version string in the minfo object
  ii.setMversion([VERSION '-->' ii.mversion]);
  
  % Add default values
  pl = applyDefaults(ii.plists, pli);
  % Tell parse that the output value for fcn should be a double so that it evals the user input
  pl = parse(pl, plist('fcn', []));
  % Set random state in case we are rebuilding and the function used rand etc
  pl.getSetRandState();
  
  fcn = find(pl, 'fcn');
  
  % Set data of analysis object
  if ischar(fcn)
    a.data  = cdata(eval(fcn));
  elseif isnumeric(fcn)
    a.data = cdata(fcn);
  else
    error('### unknown format for the function');
  end
  
  % Set non-object properties
  a.setYunits(pl.find('yunits'));
  
  % Add history
  a.addHistory(ii, pl, [], []);
  
  % Set object properties
  a.setObjectProperties(pl);
  
end