rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
extend_class_from_struct.m
1 function c = extend_class_from_struct(classname,s)
2 %function c = extend_class_from_struct(s)
3 
4 % function setting fields of a class by corresponding fields of
5 % struct s.
6 % for this, the default constructor of the string classname is
7 % called and then the member variables are copied.
8 
9 % B. Haasdonk 1.10.2013
10 
11 eval(['c = ',classname,';']);
12 fs = fields(s);
13 for i = 1:length(fs)
14  setfield(c,fs{i},getfield(s,fs{i}));
15 end;
16