How to generate a binary matrix for all possible permutations of 'i' variables X, where " i " can be any number between 1 and infinite. I know that the resultant matrix will have 2^ i unique answers, but don't know how to generate it. Let me explain by example:

variables x1, x2 (i=2) each with a possible value of 1 or 0, so the resultant matrx would be:

X2 X1

0 0

0 1

1 0

1 1

but what if i=120 for example, how do we generate the matrix for x(i) from 1 to 120? There would be 2^ 120 results.

The logic is simple, but I can not seem to translate to code:

x4 x3 x2 x1

0 0 0 0

0 0 0 1

0 0 1 0

0 0 1 1

0 1 0 0

0 1 0 1

0 1 1 0

0 1 1 1

1 0 0 0

1 0 0 1

1 0 1 0

1 0 1 1

1 1 0 0

1 1 0 1

1 1 1 0

1 1 1 1

generate matrix 2^i by i size

start with all x(i) values at 0

get value of x(i)

if x(i)=1

increment i

else set x(i)=1 then start checking values from beginning

if i reaches count of total variables for that row OR leftmost variable is 1 move to next row

or something like above

variables x1, x2 (i=2) each with a possible value of 1 or 0, so the resultant matrx would be:

X2 X1

0 0

0 1

1 0

1 1

but what if i=120 for example, how do we generate the matrix for x(i) from 1 to 120? There would be 2^ 120 results.

The logic is simple, but I can not seem to translate to code:

x4 x3 x2 x1

0 0 0 0

0 0 0 1

0 0 1 0

0 0 1 1

0 1 0 0

0 1 0 1

0 1 1 0

0 1 1 1

1 0 0 0

1 0 0 1

1 0 1 0

1 0 1 1

1 1 0 0

1 1 0 1

1 1 1 0

1 1 1 1

generate matrix 2^i by i size

start with all x(i) values at 0

get value of x(i)

if x(i)=1

increment i

else set x(i)=1 then start checking values from beginning

if i reaches count of total variables for that row OR leftmost variable is 1 move to next row

or something like above

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trialPS: I refuse to believe no one has ever had to come up with this problem before, and a true solution must exist. Come one programming experts, take a swing!

I also attached it for review purposes. The function code was hard for me to understand, I would still be interested into a more logical approach to this that's more language independent and easier to understand.

combn.m.txt

count = (2^ bits) - 1

As for your program, the notation is beyond me.

CUP, your updated script is working quite well, I will try to get a MatLab version of it up.

```
%combn.m function required
%define the matrix columns
i=5;
%create the matrix M for all binary combinations
M=combn([0 1],i);
%display M on screen
disp(M);
```

Programming Languages-Other

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

cscript bitpat.vbs

You'll get your patterns

Open in new window