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

    function B = subsref(A, S)
%SUBSREF Subsreferencing of guidarray objects
%
%  SUBSREF provides support for indexed referencing into guidarrays.  Two
%  indexing forms are supported:
%
%     G2 = G(INDEX) returns a guidarray containing guids from G
%     I = G(G2) returns an index vector containing the indices of G2 in G.

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


B = A;
% Switch on the subsref first type
switch S(1).type
    case '()'
        if length(S(1).subs) > 1
            error(message('mbc:guidarray:InvalidArgument9'));
        end
        % Get the contents of the first bracket
        S1 = S(1).subs{1};
        if isa(S1, 'guidarray')
            B = getIndices(A, S1);
        else
            % 1-D colon operator returns same thing
            if strcmp(S1, ':')
                return
            end
            % Index into array
            B.values = A.values(S1);
            % Need to check if S1 is unique - it will usually be a
            % monotonically increasing index. Note short circuit ||
            % operator to avoid sort unless required
            if ~(islogical(S1) || isMonotonic(S1) || isMonotonic(sort(S1)))
                B = makeArrayUnique(B);
            end
            % Update the hash
            B = updateHash(B);
        end
    otherwise
        error(message('mbc:guidarray:InvalidArgument10'));
end