function C = setprod(U)
% SETPROD product of multiple sets.
%
%   X = SETPROD(U) returns the cartesian product of the sets 
%   U{1},U{2}, etc, where U is a cell array composed of numeric or 
%   character arrays.  
%
%   Example: U = {[-1 -3 -5];  [10 11]; [0 1]}
% 
%   X = SETPROD(U)
%   X =
% 
%     -5    10     0
%     -3    10     0
%     -1    10     0
%     -5    11     0
%     -3    11     0
%     -1    11     0
%     -5    10     1
%     -3    10     1
%     -1    10     1
%     -5    11     1
%     -3    11     1
%     -1    11     1

% Mukhtar Ullah
% mukhtar.ullah@informatic.uni-rostock.de
% September 20, 2004

% slightly modified by Ciprian Manolescu - May 18, 2005

n = length(U);
[F{1:n}] = ndgrid(U{:});
str = ('F{}(:) ').';
str = str(:,ones(1,n));
Clist = [str(1:2,:); int2str((1:n).').'; str(3:end,:)];
C = unique(eval(['[', Clist(:).', ']']) , 'rows');
