function [b,ndx,pos] = unique(a,flag)
%UNIQUE Set unique for cell array of strings.
%   UNIQUE(A) for the cell vector A returns the same strings as in A but
%   with no repetitions.  A will be also be sorted.
%
%   [B,I,J] = UNIQUE(A) also returns index vectors I and J such
%   that B = A(I) and A = B(J) (or B = A(I,:) and A = B(J,:)).
%   
%   See also UNION, INTERSECT, SETDIFF, SETXOR, ISMEMBER.

%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 1.7 $  $Date: 2000/06/01 04:39:40 $

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

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

C = char(a);
L = cellfun('length',a);
if (size(C,1) ~= length(L))
   error('Each element in A must be a single-row text array.');
end
if ((length(L)>0) & ~all(L==L(1))), C = [C L(:)]; end

[b,ndx,pos] = unique(C,'rows');
b = reshape(a(ndx),size(ndx));

if isrow
  b = b'; 
  ndx = ndx';
  pos = pos';
end



