필터 지우기
필터 지우기

Generating input binary sequences in an order

조회 수: 5 (최근 30일)
Kash022
Kash022 2017년 10월 2일
답변: Guillaume 2017년 10월 2일
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
Jan
Jan 2017년 10월 2일
편집: Jan 2017년 10월 2일
@Stephen: I said this already. But I will remove the old hashed tags for you. Or for Kash022. Who knows.
Jan
Jan 2017년 10월 2일
@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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2017년 10월 2일
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);

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by