Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: list of all possible subsets of a set
Date: Sat, 18 Dec 2010 09:00:22 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 49
Message-ID: <ieht76$9dk$1@fred.mathworks.com>
References: <iegol3$iva$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1292662822 9652 172.30.248.37 (18 Dec 2010 09:00:22 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 18 Dec 2010 09:00:22 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:696526

"Antonis " <trelof_avoidspamremovethis@gmail.com> wrote in message <iegol3$iva$1@fred.mathworks.com>...
> I want to divide an array [1 .. N]  all integers and array is sorted
> into k segments. The output should be a list of all possible k-subset
> no permutation allowed
> 
> All subsets should have at least two elements but this is easy to do.
> 
> f.e.  k=2, N=5  ===>    a=[1 2 3 4 5]
> [1] [2 3 4 5]  less than 2 elements in set - delete
> [1 2 3 4] [5]  less than 2 elements in set - delete
> [1 2] [3 4 5]
> [1 2 3] [4 5]
> 
> k=3
> [1] [2 3] [4 5]
> [1] [2 3 4] [5]
> [1] [2] [3 4 5]
> [1 2] [3] [4 5]
> [1 2 3] [ 4] [5]
> (actually for this case there is no solution - all cases have one subset of one element.
> 
> any help appreciated. 

Again this is called *subdivision* problem, not subset, because the split happens in order. Subset is a random selection within the set.

I think I already suggest to use allVL1 function on FEX

n=5
k=3

% Engine
s = allVL1(k,n-k)+1;
splitfun = @(p) mat2cell(1:n,1,p);
c = arrayfun(@(i) splitfun(s(i,:)), 1:size(s,1), 'unif', 0);

% display
for ci=c
    cellfun(@(a) fprintf('%s ', mat2str(a)), ci{1});
    fprintf('\n'); 
end

1 2 [3 4 5] 
1 [2 3] [4 5] 
1 [2 3 4] 5 
[1 2] 3 [4 5] 
[1 2] [3 4] 5 
[1 2 3] 4 5 

Bruno