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 1984-2000 The MathWorks, Inc. 
%   $Revision: 1.7 $  $Date: 2000/06/01 04:39:41 $

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

isrow = ~((size(a,1)>1 & size(b,2)<=1) | (size(b,1)>1 & size(a,2)<=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

