Generating input binary sequences in an order
5 views (last 30 days)
Show older comments
Hi,
I have a binary sequence for a 3-bit input which goes like 0-0,0-1,...0-7 (say for a single circuit). I want to iterate this for 3 circuits...which would effectively lead to the same input transitions being repeated over (2^3)^3 times (but in different orders like 0-5,0-1,0-3, ..etc and so on..) How can I do this in MATLAB?
I tried using repmat...but it was not much of a help...Thanks!
5 Comments
Jan
on 2 Oct 2017
@Kash022: What exactly is 000? Do you mean the char vector '000'? I do not "see the sequence". What is "each column of [input2 input1 input0]"? Is it each character? Does "0-0" mean a [1 x 2] vector? If so, please do not invent a new notation using the minus operator. Standard Matlab syntax is known in the forum: [0,0]
I still do not know, what the inputs are (in Matlab syntax) and what you want to achieve.
Answers (1)
Guillaume
on 2 Oct 2017
Like others, I really don't understand the syntax 0-0, 0-7. I get that you've got 8 different possibilities (0 to 7) for choosing two bits at a time, but I've no idea what the 0- represent, nor how you encode that in matlab.
Anyway, there are two easy way to generate all permutations of choosing n elements at a time of a set of size s:
- Using dec2base, this is limited to sets of size 10 at most:
n = 3;
s = 8;
permutations = dec2base(0:s^n-1, s) - '0'
- Using ndgrid, this is less limited, but more lines of code:
n = 3;
s = 8;
permutations = cell(1, n);
[permutations{:}] = ndgrid(0:s-1);
permutations = reshape(cat(n+1, permutations{:}), [], n)
From there, you can change the permutation matrix to whatever you want, e.g. if you wanted to write the 0-7 as char arrays '0-0' to '0-7', then:
fullset = compose('0-%d', 0:7);
0 Comments
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!