Mercurial > hg > ltpda
diff m-toolbox/classes/+utils/@prog/struct2obj.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/+utils/@prog/struct2obj.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,44 @@ +% STRUCT2OBJ converts the input structure into the given object. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% DESCRIPTION: STRUCT2OBJ converts the input structure into the given object. +% +% CALL: obj = struct2obj(s, class) +% +% INPUTS: s - the structure to convert +% class - the class of the object to convert to +% +% +% OUTPUTS: obj - the converted object +% +% VERSION: $Id: struct2obj.m,v 1.2 2008/07/03 18:20:25 ingo Exp $ +% +% HISTORY: 09-05-07 M Hewitson +% Creation +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +function varargout = struct2obj(varargin) + +% Get inputs +if isstruct(varargin{1}) + s = varargin{1}; +else + error('### Incorrect usage. The first argument should be a structure.'); +end +if ischar(varargin{2}) + cl = varargin{2}; +else + error('### Incorrect usage. The second argument should be a class name (string).'); +end + +% Make an empty object +eobj = eval(cl); +% Get the specification of the required type +fnames = fieldnames(eobj); + +% Loop over fields and try to set them from the structure + + +% Set output +varargout{1} = []; \ No newline at end of file