how would I randomly replace two elements in a row vector

rn, i have:
y = char(randperm(27));
for i = 1:iter
ynew = randperm(numel(y), 2);

回答 (1 件)

Walter Roberson
Walter Roberson 2024 年 2 月 13 日
編集済み: Walter Roberson 2024 年 2 月 13 日

0 投票

y = char(randperm(27) - 1 + 'A');
for i = 1:iter
idx = randperm(numel(y), 2);
ynew = y;
ynew(idx) = ynew([idx(2) idx(1)]);
end

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2024 年 2 月 13 日

編集済み:

2024 年 3 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by