フィルターのクリア

How to make combinations of given condition?

2 ビュー (過去 30 日間)
C Zeng
C Zeng 2012 年 12 月 28 日
Hi, all,
For example, if I want to make all combination of 5-dim vectors have only 2 two's, other entries are all 0. Is there a command in Matlab can do it? That is 22000 20200 20020 20002 02200 02020 02002 00220 00202 00022
Thanks.

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 12 月 28 日
編集済み: Andrei Bobrov 2012 年 12 月 28 日
k = dec2bin(0:sum(pow2(0:4)))-'0';
out = 2*k(sum(k,2) == 2,:);
  1 件のコメント
C Zeng
C Zeng 2012 年 12 月 28 日
Andrei, thanks, can you explain?
Actually I want all other entries to be 1. Is there a way to do it easily?
I tried your code, it works here though not understood here. :-(

サインインしてコメントする。

その他の回答 (1 件)

Roger Stafford
Roger Stafford 2012 年 12 月 28 日
This is a problem for matlab's 'nchoosek' function.
  1 件のコメント
C Zeng
C Zeng 2013 年 1 月 1 日
Thanks, got it!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by