function out = combinat(obj, n)
%	out = combinat(obj, n) returns combinations of obj with n distinct
%	elements.
%	For instance: combinat([1 2 3 4 5], 2) or combinat('abcde', 3).

%	Roger Jang, Sept-21-1996

if n == 1,
	out = obj(:);
	return;
end

out = [];
for i = 1:length(obj)-1,
	first = obj(i);
	tail = obj(i+1:length(obj));
	tail_combinat = combinat(tail, n-1);
	loop_out = [first*ones(size(tail_combinat,1), 1), tail_combinat]; 
	out = [out; loop_out];
end
