comparison m-toolbox/classes/@ssm/fromStruct.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 % FROMSTRUCT creates from a structure an SSM object.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % FUNCTION: fromStruct
5 %
6 % DESCRIPTION: Creates from a structure an SSM object.
7 %
8 % CALL: obj = fromStruct(obj, struct)
9 %
10 % VERSION: $Id: fromStruct.m,v 1.11 2011/03/28 17:02:29 ingo Exp $
11 %
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13
14 function objs = fromStruct(objs, obj_struct)
15
16 % Get the class name of the object.
17 cn = class(objs);
18
19 % Define function name for updating the structure
20 fcnName = ([cn '.update_struct']);
21
22 % Initialize output objects
23 objs = feval([cn '.initObjectWithSize'], size(obj_struct, 1), size(obj_struct, 2));
24
25 % Update structure (if necessary)
26 for kk = 1:numel(obj_struct)
27
28 % Get structure version
29 if isfield(obj_struct, 'tbxver')
30 tbxVer = obj_struct(kk).tbxver;
31 else
32 tbxVer = '1.0';
33 end
34 % Update structure
35 up_struct = feval(fcnName, obj_struct(kk), tbxVer);
36
37 % Call super-class
38 objs(kk) = fromStruct@ltpda_uoh(objs(kk), up_struct);
39
40 % Set 'amats'
41 if isfield(up_struct, 'amats')
42 objs(kk).amats = up_struct.amats;
43 end
44
45 % Set 'bmats'
46 if isfield(up_struct, 'bmats')
47 objs(kk).bmats = up_struct.bmats;
48 end
49
50 % Set 'cmats'
51 if isfield(up_struct, 'cmats')
52 objs(kk).cmats = up_struct.cmats;
53 end
54
55 % Set 'dmats'
56 if isfield(up_struct, 'dmats')
57 objs(kk).dmats = up_struct.dmats;
58 end
59
60 % Set 'timestep'
61 if isfield(up_struct, 'timestep')
62 objs(kk).timestep = up_struct.timestep;
63 end
64
65 % Set 'inputs' object
66 if isfield(up_struct, 'inputs')
67 objs(kk).inputs = utils.helper.getObjectFromStruct(up_struct.inputs);
68 end
69
70 % Set 'states' object
71 if isfield(up_struct, 'states')
72 objs(kk).states = utils.helper.getObjectFromStruct(up_struct.states);
73 end
74
75 % Set 'outputs' object
76 if isfield(up_struct, 'outputs')
77 objs(kk).outputs = utils.helper.getObjectFromStruct(up_struct.outputs);
78 end
79
80 % Set 'numparams' object
81 if isfield(up_struct, 'numparams')
82 objs(kk).numparams = utils.helper.getObjectFromStruct(up_struct.numparams);
83 end
84
85 % Set 'params' object
86 if isfield(up_struct, 'params')
87 objs(kk).params = utils.helper.getObjectFromStruct(up_struct.params);
88 end
89
90 end
91
92 end
93