Mercurial > hg > ltpda
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % STRUCT2OBJ converts the input structure into the given object. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: STRUCT2OBJ converts the input structure into the given object. | |
5 % | |
6 % CALL: obj = struct2obj(s, class) | |
7 % | |
8 % INPUTS: s - the structure to convert | |
9 % class - the class of the object to convert to | |
10 % | |
11 % | |
12 % OUTPUTS: obj - the converted object | |
13 % | |
14 % VERSION: $Id: struct2obj.m,v 1.2 2008/07/03 18:20:25 ingo Exp $ | |
15 % | |
16 % HISTORY: 09-05-07 M Hewitson | |
17 % Creation | |
18 % | |
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
20 | |
21 function varargout = struct2obj(varargin) | |
22 | |
23 % Get inputs | |
24 if isstruct(varargin{1}) | |
25 s = varargin{1}; | |
26 else | |
27 error('### Incorrect usage. The first argument should be a structure.'); | |
28 end | |
29 if ischar(varargin{2}) | |
30 cl = varargin{2}; | |
31 else | |
32 error('### Incorrect usage. The second argument should be a class name (string).'); | |
33 end | |
34 | |
35 % Make an empty object | |
36 eobj = eval(cl); | |
37 % Get the specification of the required type | |
38 fnames = fieldnames(eobj); | |
39 | |
40 % Loop over fields and try to set them from the structure | |
41 | |
42 | |
43 % Set output | |
44 varargout{1} = []; |