function [c,ia,ib] = union(a,b,flag)
%UNION  Set union for cell array of strings.
%   UNION(A,B) when A and B are vectors returns the combined values
%   from A and B but with no repetitions.  The result will be sorted.
%
%   [C,IA,IB] = UNION(A,B) also returns index vectors IA and IB such
%   that C is a sorted combination of the elements A(IA) and B(IB).
%
%   See also UNIQUE, INTERSECT, SETDIFF, SETXOR, ISMEMBER.

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

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

if ischar(a), a = cellstr(a); end
if ischar(b), b = cellstr(b); end

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

[c,ndx] = unique([a;b]);
if isrow, c = c'; ndx = ndx'; end

if nargout>1, % Create index vectors.
  n = length(a);
  d = ndx > n;
  ia = ndx(~d);
  ib = ndx(d)-n;
end
