A solution could be ..
>> data = {'high', 'high', 'high', 'medium', 'low', 'low', 'low', 'medium', ...
'low', 'medium', 'medium', 'medium', 'high', 'medium'} ;
>> dataItems = unique(data)
dataItems =
'high' 'low' 'medium'
>> n = numel(dataItems) ;
>> combs = arrayfun(@(k)dataItems(combntns(1:n,k)), 1:n, 'UniformOutput', false)
>> combs{1}
ans =
'high' 'low' 'medium'
>> combs{2}
ans =
'high' 'low'
'high' 'medium'
'low' 'medium'
>> combs{3}
ans =
'high' 'low' 'medium'
To understand the internals, look at what we get when we evaluate
>> ids = arrayfun(@(k)combntns(1:n,k), 1:n, 'UniformOutput', false)
ids =
[3x1 double] [3x2 double] [1x3 double]
>> ids{1}
ans =
1
2
3
>> ids{2}
ans =
1 2
1 3
2 3
>> ids{3}
ans =
1 2 3
so, what we do when we compute combs is to use these ids to index relevant items in dataItems.
Hope it helps!
PS: this is the power set minus the empty set. When you say that you don't want the "power set", do you mean actually that you don't want the set of all elements? If so, you can just replace n by n-1 in the call to ARRAYFUN: >> combs = arrayfun(@(k)dataItems(combntns(1:n,k)), 1:n-1, 'UniformOutput', false)
combs =
{1x3 cell} {3x2 cell}
>> combs{1}
ans =
'high' 'low' 'medium'
>> combs{2}
ans =
'high' 'low'
'high' 'medium'
'low' 'medium'
Best Answer