comparison m-toolbox/classes/@stattest/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 Construct a ltpda_obj from a struct
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % FUNCTION: fromStruct
5 %
6 % DESCRIPTION: Construct a ltpda_obj from a struct
7 %
8 % CALL: obj = fromStruct(obj, struct)
9 %
10 % VERSION: $Id: fromStruct.m,v 1.1 2010/12/20 12:50:15 hewitson Exp $
11 %
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13
14 function objs = fromStruct(objs, obj_struct)
15
16 cn = class(objs);
17
18 % build/update struct
19 for kk = 1:numel(obj_struct)
20
21 objs(kk) = feval(cn);
22 %%% Update the structure to the current toolbox version
23 if isfield(obj_struct, 'tbxver')
24 fcn_name = ([cn '.update_struct']);
25 up_struct = feval(fcn_name, obj_struct(kk), obj_struct(kk).tbxver);
26 else
27 up_struct = obj_struct(kk);
28 end
29
30 props = properties(cn);
31 nprops = numel(props);
32
33 for jj=1:nprops
34 prop = props{jj};
35 if isfield(up_struct, prop) && isstruct(up_struct.(prop))
36 % what class?
37 if isfield(up_struct.(prop), 'class')
38 objs(kk).(prop) = utils.helper.struct2obj(up_struct.(prop), up_struct.(prop).class);
39 else
40 % can we guess class ?
41 cln = utils.helper.classFromStruct(up_struct.(prop));
42 if ~isempty(cln)
43 objs(kk).(prop) = feval(cln, up_struct.(prop));
44 else
45 if isfield(up_struct, prop)
46 objs(kk).(prop) = up_struct.(prop);
47 end
48 end
49 end
50 else
51 if isfield(up_struct, prop)
52 % ATTENTION: Special case for 'ntaps'
53 % It is not necessary to set this value because it
54 % will be computed.
55 if ~strcmp(prop, 'ntaps')
56 objs(kk).(prop) = up_struct.(prop);
57 end
58 end
59 end
60 end
61
62 end
63
64 % Reshape the objects
65 objs = reshape(objs, size(obj_struct));
66
67 end
68