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

    function index = getIndices(obj, indexer)
%GETINDICES Find guids from one guidarray in another
%
%  IDX = FINDINDEX(G, G2) finds the guids in G2 in G and returns their
%  indices.

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


% Check for empty indexing
if isempty(obj) || isempty(indexer)
    index = zeros(size(indexer));
    return
end

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

[sortedValues, sortedIndex] = getHash(obj);

% TO DO - Faster find than ismembc2 which makes use of both hash's
% Find indexer values in obj hash table
i = ismembc2(indexer.values, sortedValues);

% Output the real index not the sorted index
index = zeros(length(i), 1);
NON_ZERO = i > 0;
index(NON_ZERO) = sortedIndex(i(NON_ZERO));