w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Matlab- Combinations for subsets of a set

You can use a loop there or arrayfun which is just a compact way to express such a loopy approach and not a vectorized approach -

combs = arrayfun(@(x) nchoosek(S,x),3:numel(S),'Uniform',0)

The output would be a cell array with each cell representing values for each combination. So, when you run the code, you would get -

>> combs{1}
ans =
     2     7     4
     2     7     1
     2     7     9
     2     4     1
     2     4     9
     2     1     9
     7     4     1
     7     4     9
     7     1     9
     4     1     9

which would be your 3-combinations set.

>> combs{2}
ans =
     2     7     4     1
     2     7     4     9
     2     7     1     9
     2     4     1     9
     7     4     1     9

would be your 4-combinations set and so on.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.