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

    function B = subsasgn(A, S, data)
%SUBSASGN Subsasigning of GUIDARRAY objects
%
%  SUBSASGN provides support for indexed assignment into guidarrays of the
%  form G(IDX) = G2.

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


B = A;

% Check type of data
if ~isempty(data) && ~isa(data, 'guidarray')
    error(message('mbc:guidarray:InvalidArgument6'));
end

% Switch on the subsref first type
switch S(1).type
    case '()'
        if length(S(1).subs) > 1
            error(message('mbc:guidarray:InvalidArgument7'));
        end
        % Get the contents of the first bracket
        S1 = S(1).subs{1};
        if isempty(data)
            B.values(S1) = [];
        else
            % Index into array
            B.values(S1) = data.values;
            % Ensure uniqueness
            % TODO - this could use the same merging algorithm as vertcat to
            % ensure uniquness
            B = makeArrayUnique(B);
        end
        % Update the hash
        B = updateHash(B);
    otherwise
        error(message('mbc:guidarray:InvalidArgument8'));
end