How to rearrange random binary input for each iteration?

2 ビュー (過去 30 日間)
ASHA PON
ASHA PON 2023 年 1 月 9 日
コメント済み: ASHA PON 2023 年 1 月 10 日
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
Bjorn Gustavsson 2023 年 1 月 9 日
Have a look at the nextperm tool on the file exchange. It will allow you to cycle through all permutations.
HTH
  9 件のコメント
Walter Roberson
Walter Roberson 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
row = 1×12
1 0 1 1 1 1 1 0 1 0 0 0
result = -6
row = 1×12
1 1 1 1 0 1 0 0 1 0 0 0
result = 1
row = 1×12
1 0 1 1 0 1 1 0 0 1 0 0
result = 17
row = 1×12
1 0 1 0 0 0 1 0 1 0 1 1
result = -6
row = 1×12
1 1 0 0 1 1 0 0 1 1 0 0
result = -3
ASHA PON
ASHA PON 2023 年 1 月 10 日
Thank you for the reply

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by