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일
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 Exchange에서 Creating 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