Path: news.mathworks.com!not-for-mail
From: "Isaac " <asimov4000@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Help to Write code to Create Binary Vectors
Date: Thu, 20 Oct 2011 17:01:27 +0000 (UTC)
Organization: Asimov Fin
Lines: 21
Message-ID: <j7pk57$qbq$1@newscl01ah.mathworks.com>
Reply-To: "Isaac " <asimov4000@hotmail.com>
NNTP-Posting-Host: www-01-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1319130087 27002 172.30.248.46 (20 Oct 2011 17:01:27 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Oct 2011 17:01:27 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1380234
Xref: news.mathworks.com comp.soft-sys.matlab:746631

Hi All!

I have to write a code which generates all the possibile binary vectors (i.e. vectors whose elements can be only 0 or 1) which a determined length and "numbers of ones".

For example

lenght=3
number of ones=2

my function should return me the following matrix (one row = one combination):

[1 1 0; 
1 0 1; 
0 1 1]


could you suggest me any efficient way to do it?

Thanks in advance

Asi