⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 set.m

📁 particle filter 粒子滤波器 matlab工具箱
💻 M
字号:
function objout = set(obj,varargin)
% Sets the properties of an object.
%
% set(obj, 'propertyname', value) sets the property 'propertyname' of the object 'obj'
% to the value 'value'. 
%
% An equivalent syntax is obj.propertyname = value.
%
% set(obj, 'property1', value1, 'property2', value2, ...) sets multiple property values.
% set(obj, 'property') displays legitimate values for the specified property of 'obj'.
% set(obj) displays all properties of 'obj' and their admissible values.
%
% If an output argument is specified, the modified object will be assigned to this and
% no modifications will be done to the input object.
%
% Type 'props(obj)' for more details on the properties of the object 'obj'.

% Toolbox for nonlinear filtering.
% Copyright (C) 2005  Jakob Ros閚 <jakob.rosen@gmail.com>
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

if nargin==1
	% Only 'obj' is supplied. Display the list of properties.
	displayprops(obj);
elseif nargin==2;
	% A parameter was given, but no value. Display information about the property.
	prop_name = varargin{1};
	[props,rprops]=pnames;
	if findcstr(props,prop_name)||findcstr(rprops,prop_name)
		disp(pformat(get(obj,prop_name)));
	else
		error('Unknown property');
	end
else
	if isempty(inputname(1))&&nargout<1
		error('The first argument must be a named variable if no output argument is given.')
	elseif rem(nargin-1,2)~=0,
		error('Property/value pairs must come in even number.')
	end

	property_argin = varargin;
	while length(property_argin) >= 2,
		prop_name = property_argin{1};
		v = property_argin{2};
		property_argin = property_argin(3:end);
		switch prop_name

		% <custom>
		% Here we handle properties that need custom treatment (or need to be 
		% processed really fast)

		case {'R'}
			obj.R=v;
			obj.Rsqrtm=sqrtm(v);
			obj.R_str=expr2str(v);
			n=length(v);
			obj.n=n;
			% "Ugly" hack to make things work.
			% We need to think about a solution.
			mu=obj.mu;
			if length(mu)>n;
				obj.mu=mu(1:n);
			elseif length(mu)<n
				mu(end+1:n)=zeros(n-length(mu),1);
				obj.mu=reshape(mu,n,1);
			end		

		case {'R_str'}
			expr=str2expr(v);
			obj.R=expr;
			obj.Rsqrtm=sqrtm(expr);
			obj.R_str=expr2str(expr);	% Covert again to format it properly
			n=length(expr);
			obj.n=n;
			% "Ugly" hack to make things work.
			% We need to think about a solution.
			mu=obj.mu;
			if length(mu)>n;
				obj.mu=mu(1:n);
			elseif length(mu)<n
				mu(end+1:n)=zeros(n-length(mu),1);
				obj.mu=reshape(mu,n,1);
			end		

		% </custom>

		otherwise
			[props,rprops]=pnames;
			if findcstr(props,prop_name)
				eval(strcat('obj.',prop_name,'=v;'));
			elseif findcstr(rprops,prop_name)
				error([prop_name,' is a read-only property'])
			else
				error([prop_name,' is not a valid property'])
			end
		end
	end

	if nargout==0
		% No output variable was specified by the user.
		% We'll do the assignment manually in the caller's workspace.
		objname = inputname(1);
		assignin('caller',objname,obj)
	else
		objout=obj;
	end;
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -