comparison m-toolbox/classes/@paramValue/setProperty.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 % SETPROPERTY set a property to a paramValue
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SETPROPERTY set a property to a paramValue. If the property
5 % name exists then replace the value otherwise add this
6 % property.
7 %
8 % CALL: obj = obj.setProperty(propertyName, value);
9 %
10 % INPUTS: propertyName: Property name of the paramValue object
11 % value: Value of the property
12 %
13 % VERSION: $Id: setProperty.m,v 1.2 2010/09/28 17:49:27 ingo Exp $
14 %
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16
17 function obj = setProperty(obj, propertyName, value)
18
19 if nargin ~= 3
20 error('### This method works only with three inputs.');
21 end
22
23 obj = copy(obj, nargout);
24
25 if isempty(obj.property)
26 % ATTENTION: It is necessary for the STRUCT method to use a different
27 % command if the value is a cell.
28 if iscell(value)
29 obj.property = struct(propertyName, {value});
30 else
31 obj.property = struct(propertyName, value);
32 end
33 else
34 obj.property.(propertyName) = value;
35 end
36
37 end