How to rearrange random binary input for each iteration?
이전 댓글 표시
I am having 7 randomnly generated binary input. With this input I have performed some set of mathematical calculations. Now i need to repeat the mathematical calculations with changed order of binary input and this has to be followed for each iteration until a certain condition is met.
Example:
A = [011; 101; 010; 001; 100; 110; 111]
Expected output: Input order of A has to be varied for each iteration.
답변 (1개)
Bjorn Gustavsson
2023년 1월 9일
0 개 추천
Have a look at the nextperm tool on the file exchange. It will allow you to cycle through all permutations.
HTH
댓글 수: 9
ASHA PON
2023년 1월 10일
This does not give a binary vector
A = [011; 101; 010; 001; 100; 110; 111]
Those are decimal, base 10 numbers, not base 2 numbers.
Please attach your actual code.
A = randperm(7)
for col = (dec2bin(A) - '0').'
row = col.'
result = row(1)*11 + row(2).^2 - row(3) %some calculation
end
ASHA PON
2023년 1월 10일
Walter Roberson
2023년 1월 10일
The number does vary for each iteration. Each row = output line shows the input that was received, and you can see that no two of the inputs were the same.
ASHA PON
2023년 1월 10일
Just write the expression using indexing.
If you have a linear expression, you could use multiplication such as [3 -1 5 11 4 2 -5 ...] * col
A = randi([0 2^12-1], 1, 5)
for col = (dec2bin(A) - '0').'
row = col.'
result = row(1)*11 + row(2).^2 - row(3) + 7*row(4).^2 - row(5).^9 + row(6)*2 - row(7)*5 + row(8).^3 - row(9)*15 + row(10)*3 + row(11)*8 - row(9)*4 %some calculation
end
ASHA PON
2023년 1월 10일
카테고리
도움말 센터 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!