Generating all combinations containing at least one element of a given set in Matlab

后端 未结 3 1648
刺人心
刺人心 2020-12-31 17:06

I use combnk to generate a list of combinations. How can I generate a subset of combinations, which always includes particular values. For example, for co

3条回答
  •  说谎
    说谎 (楼主)
    2020-12-31 17:32

    Just to improve Steve's answer : in your case (you want all combinations with 3 and/or 5) it will be

    • all k-1/n-2 combinations with 3 added
    • all k-1/n-2 combinations with 5 added
    • all k-2/n-2 combinations with 3 and 5 added

    Easily generalized for any other case of this type.

提交回复
热议问题