function [c,ia,ib] = intersect(a,b,flag)
%INTERSECT Set intersection for cell array of strings.
%   INTERSECT(A,B) when A and B are cell arrays of strings returns the 
%   strings common to both A and B. The result will be sorted.
%
%   [C,IA,IB] = INTERSECT(A,B) also returns index vectors IA and IB
%   such that C = A(IA) and C = B(IB).
%
%   See also UNIQUE, UNION, SETDIFF, SETXOR, ISMEMBER.

%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 1.5 $  $Date: 1998/05/20 15:22:38 $

if nargin>2, error('''rows'' flag not supported for cell arrays.'); end

isrow = ndims(a)==2 & size(a,1)==1 & ndims(b)==2 & size(b,1)==1;

[c,ia,ib] = intersect(char(a),char(b),'rows');
if iscell(a),
  c = reshape(a(ia),size(ia));
else
  c = reshape(b(ib),size(ib));
end

if isrow
  c = c';
  ia = ia';
  ib = ib';
end

