필터 지우기
필터 지우기

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.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by