How to get all possible permutations in binary format?

4 views (last 30 days)
Hello, I want to get possible permutation of the vector v which actually contains a boolean values. Suppose the first permutation is v=[b2 b3 b1] . So it put the second column first then third column and finally the first colum and convert it into decimals
B=[0,1,0;0,0,1;1,1,0;0,1,1;1,0,1;1,0,0];
b1=B(:,1);
b2=B(:,2);
b3=B(:,3);
v=[b1 b2 b3];
c=perms(v);
final =bi2de(c)
  2 Comments
lilly lord
lilly lord on 29 Apr 2022
v=[b1 b2 b3] I want to permute v ,for exapmle v=[b1,b3 b2] then v=[b3 ,b2,b1] and by doing so it actually takes the valurs for b1=B(:,1) etc. I need different decimal values after each permutation

Sign in to comment.

Accepted Answer

DGM
DGM on 29 Apr 2022
Edited: DGM on 30 Apr 2022
I'm not sure, but are you thinking of something like this?
B = [0,1,0;0,0,1;1,1,0;0,1,1;1,0,1;1,0,0];
% all permutations of the columns of B
v = B(:,perms(1:size(B,2)));
v = reshape(v.',3,[]).'
v = 36×3
0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 1 0 0 0 0 0 0 1 0 1 0
% convert to dec
c = bi2de(v,'left-msb')
c = 36×1
1 4 4 1 2 2 6 0 1 2
  3 Comments
lilly lord
lilly lord on 2 May 2022
Thank you sir. YOur answer clearify the problem I am facing.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!