Initial commit
[pftoolbox.git] / noise / @gauss / set.m
blob97f59b147bb796a97932db440d12a5ddbb54c732
1 function objout = set(obj,varargin)\r
2 % Sets the properties of an object.\r
3 %\r
4 % set(obj, 'propertyname', value) sets the property 'propertyname' of the object 'obj'\r
5 % to the value 'value'. \r
6 %\r
7 % An equivalent syntax is obj.propertyname = value.\r
8 %\r
9 % set(obj, 'property1', value1, 'property2', value2, ...) sets multiple property values.\r
10 % set(obj, 'property') displays legitimate values for the specified property of 'obj'.\r
11 % set(obj) displays all properties of 'obj' and their admissible values.\r
12 %\r
13 % If an output argument is specified, the modified object will be assigned to this and\r
14 % no modifications will be done to the input object.\r
15 %\r
16 % Type 'props(obj)' for more details on the properties of the object 'obj'.\r
18 % Toolbox for nonlinear filtering.\r
19 % Copyright (C) 2005  Jakob Rosén <jakob.rosen@gmail.com>\r
20 %\r
21 % This program is free software; you can redistribute it and/or\r
22 % modify it under the terms of the GNU General Public License\r
23 % as published by the Free Software Foundation; either version 2\r
24 % of the License, or (at your option) any later version.\r
25 %\r
26 % This program is distributed in the hope that it will be useful,\r
27 % but WITHOUT ANY WARRANTY; without even the implied warranty of\r
28 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
29 % GNU General Public License for more details.\r
30 %\r
31 % You should have received a copy of the GNU General Public License\r
32 % along with this program; if not, write to the Free Software\r
33 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
35 if nargin==1\r
36         % Only 'obj' is supplied. Display the list of properties.\r
37         displayprops(obj);\r
38 elseif nargin==2;\r
39         % A parameter was given, but no value. Display information about the property.\r
40         prop_name = varargin{1};\r
41         [props,rprops]=pnames;\r
42         if findcstr(props,prop_name)||findcstr(rprops,prop_name)\r
43                 disp(pformat(get(obj,prop_name)));\r
44         else\r
45                 error('Unknown property');\r
46         end\r
47 else\r
48         if isempty(inputname(1))&&nargout<1\r
49                 error('The first argument must be a named variable if no output argument is given.')\r
50         elseif rem(nargin-1,2)~=0,\r
51                 error('Property/value pairs must come in even number.')\r
52         end\r
54         property_argin = varargin;\r
55         while length(property_argin) >= 2,\r
56                 prop_name = property_argin{1};\r
57                 v = property_argin{2};\r
58                 property_argin = property_argin(3:end);\r
59                 switch prop_name\r
61                 % <custom>\r
62                 % Here we handle properties that need custom treatment (or need to be \r
63                 % processed really fast)\r
65                 case {'R'}\r
66                         obj.R=v;\r
67                         obj.Rsqrtm=sqrtm(v);\r
68                         obj.R_str=expr2str(v);\r
69                         n=length(v);\r
70                         obj.n=n;\r
71                         % "Ugly" hack to make things work.\r
72                         % We need to think about a solution.\r
73                         mu=obj.mu;\r
74                         if length(mu)>n;\r
75                                 obj.mu=mu(1:n);\r
76                         elseif length(mu)<n\r
77                                 mu(end+1:n)=zeros(n-length(mu),1);\r
78                                 obj.mu=reshape(mu,n,1);\r
79                         end             \r
81                 case {'R_str'}\r
82                         expr=str2expr(v);\r
83                         obj.R=expr;\r
84                         obj.Rsqrtm=sqrtm(expr);\r
85                         obj.R_str=expr2str(expr);       % Covert again to format it properly\r
86                         n=length(expr);\r
87                         obj.n=n;\r
88                         % "Ugly" hack to make things work.\r
89                         % We need to think about a solution.\r
90                         mu=obj.mu;\r
91                         if length(mu)>n;\r
92                                 obj.mu=mu(1:n);\r
93                         elseif length(mu)<n\r
94                                 mu(end+1:n)=zeros(n-length(mu),1);\r
95                                 obj.mu=reshape(mu,n,1);\r
96                         end             \r
98                 % </custom>\r
100                 otherwise\r
101                         [props,rprops]=pnames;\r
102                         if findcstr(props,prop_name)\r
103                                 eval(strcat('obj.',prop_name,'=v;'));\r
104                         elseif findcstr(rprops,prop_name)\r
105                                 error([prop_name,' is a read-only property'])\r
106                         else\r
107                                 error([prop_name,' is not a valid property'])\r
108                         end\r
109                 end\r
110         end\r
112         if nargout==0\r
113                 % No output variable was specified by the user.\r
114                 % We'll do the assignment manually in the caller's workspace.\r
115                 objname = inputname(1);\r
116                 assignin('caller',objname,obj)\r
117         else\r
118                 objout=obj;\r
119         end;\r
120 end\r