www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@designdev/subsasgn.m

    function newobj = subsasgn(obj, S, data)
% DESIGNDEV/SUBSASGN overloaded subsasgn operator

%  Copyright 2000-2011 The MathWorks, Inc. and Ford Global Technologies, Inc.




% Get the cell array of DesignDev objects
objs = DesignDev2Cell(obj);

% Initially assume we are operating on all the objects unless some
% are specifically mentioned
affectedObjects = 1:count(obj);

% Are some objects specifically mentioned? If so, they are the numeric values
% in S(1).subs{1}. Note '(:)' would fail the isnumeric and so affect all objs 
if strcmp(S(1).type, '()') 
	if isnumeric(S(1).subs{1})
		affectedObjects = S(1).subs{1};
	end
	% Remove S(1) from the input
	S = S(2:end);
else
	% Here we have come in with something like obj.getConstraints
	% which has the meaning obj(end).getConstraints because of the 
	% way in which designdev objects are stored
	affectedObjects = length(objs);
end
	
% Do we have any more inputs? If not create a DesignDev object where the
% affectedObjects are replaced with data
if isempty(S) && isa(data,'designdev')
%%%%%%%% TO DO - affectedObjects could have length greater than 1
	newobjs = DesignDev2Cell(data);
	objs(affectedObjects) = newobjs;
elseif S(1).type == '.' 
	S2= S(2:end);
	for i = affectedObjects
		switch lower(S(1).subs)
		case 'basemodel'
			objs = i_assignModel(objs, data, i,S2);
		case 'designtree'
			objs = i_assignTree(objs, data, i,S2);
		case 'constraints'
			objs = i_assignConstraints(objs, data, i);
		case 'design'
			objs = i_assignDesign(objs, data, i);
		case 'data'
			objs = i_assignData(objs, data, i, S2);
		case 'currentpoint'
			objs{i}.currentPoint = data;
		otherwise
			error(message('mbc:designdev:InvalidPropertyName'));
		end
	end
end

% Recreate the whole DesignDev object from the cell array of DesignDev objects
newobj = Cell2DesignDev(objs);

%----------------------------------------------
% Subfunction i_assignConstrinaints
%----------------------------------------------
function objs = i_assignConstraints(objs, data, i)

objs{i}.constraints = data;

%----------------------------------------------
% Subfunction i_assignDesign
%----------------------------------------------
function objs = i_assignDesign(objs, data, i)

if isa(data, 'xregdesign')
	objs{i}.design = data;
	% update the design as well
	dtree= objs{i}.DesignTree;
	if ~dtree.chosen
		dtree.chosen= length(dtree.designs)+1;
	end
	dtree.designs{dtree.chosen}= data;
	objs{i}.DesignTree= dtree;
else
	error(message('mbc:designdev:InvalidPropertyValue'));
end

%----------------------------------------------
% Subfunction i_assignData
%----------------------------------------------
function objs = i_assignData(objs, newData, i, S)
% Note that S represents passing on of subsasgn parameters
if isempty(S)
	objs{i}.data = newData;
else
	data = objs{i}.data;
    % Need to check if data is an object or not because if newData is also and object
    % then subsasgn(data, S, newData) calls class(newData)/subsasgn and not builtin/subsasgn
	if isobject(data)
		objs{i}.data = subsasgn(data, S, newData);
	else
		objs{i}.data = builtin('subsasgn', data, S, newData);
	end
end


%----------------------------------------------
% Subfunction i_assignModel
%----------------------------------------------
function objs = i_assignModel(objs, NewModel, i, S)
% Note that S represents passing on of subsasgn parameters
if isempty(S)
	objs{i} = setmodel(objs{i} , NewModel);
else
	error(message('mbc:designdev:InvalidArgument5'))
end

%----------------------------------------------
% Subfunction i_assignModel
%----------------------------------------------
function objs = i_assignTree(objs, NewTree, i, S)
% Note that S represents passing on of subsasgn parameters
if isempty(S)
	objs{i}.DesignTree = NewTree;
else
	error(message('mbc:designdev:InvalidArgument6'))
end