Do you have such tiny inputs in all cases? Then a linear search is faster than the smart sorting of intersect and the binary search:
X = [21 32 33 41 28 91 30];
tic; for k = 1:1e5; [~, ind] = intersect(Y, X); end; toc
tic; for k = 1:1e5; ind = AinBidxLin(Y, X); end; toc
tic; for k = 1:1e5; ind = AinBidx(Y, X); end; toc
function Ai = AinBidxLin(A, B)
if ~isempty(find(A(iA) == B, 1))
function Ai = AinBidx(A, B)
Ai = find(ismembc(A(:), sort(B(:))));
If the inputs are not tiny, use the ismembc appraoch. This is the core of intersect also, but unfortunately it is not documented. Maybe this compiled C-Mex function will be removed in future Matlab versions.
[EDITED] Some further tests let me prefer the ismembc approach for all inputs, even very small ones. Please try this by your own.
The set functions intersect, setdiff, union has been accelerated in modern Matlab versions. But at least at Matlab online, ismembc is still 10 times faster.