Generating input binary sequences in an order

5 Ansichten (letzte 30 Tage)
Kash022
Kash022 am 2 Okt. 2017
Beantwortet: Guillaume am 2 Okt. 2017
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 Kommentare
Jan
Jan am 2 Okt. 2017
Bearbeitet: Jan am 2 Okt. 2017
@Stephen: I said this already. But I will remove the old hashed tags for you. Or for Kash022. Who knows.
Jan
Jan am 2 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Guillaume
Guillaume am 2 Okt. 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);

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by