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

    function [OK, location] = ismember(obj, indexer)
%ISMEMBER Check whether guids in one array are contained in another
%
%  [IN, LOC] = ISMEMBER(G1, G2) checks whether each guid in G1 is in the
%  guidarray G2.  A logical array the same size as G1 is returned in IN.
%  The indices of the matching guids are returned in LOC.  LOC will
%  contains a zero for each guid that does not have a match in G2.

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


% Check that indexer is a GUIDARRAY
if ~isa(indexer, 'guidarray')
    error(message('mbc:guidarray:InvalidArgument5'));
end

[sortedValues, sortedIndex] = getHash(indexer);

% TO DO - Faster find than ismembc2 which makes use of both hash's
% Find indexer values in obj hash table
if nargout < 2
    OK = ismembc(obj.values, sortedValues);
else
    % Find the locations using the ismembc2 member function
    location = ismembc2(obj.values, sortedValues);
    
    % Then get the OK flags from the locations
    OK = location > 0;
    
    % Reindex
    location(OK) = sortedIndex(location(OK));
end