How to randomly change a digit in a string

I have a string = 00101 How i can randomly change one digits of that string? Ex: 00101=>00100

 採用された回答

Joseph Wilson
Joseph Wilson 2020 年 12 月 22 日

0 投票

string1 = '00101';
digit_change = randi(length(string1));
digit_val = str2num(string1(digit_change));
digit_new = num2str(~digit_val);
string1(digit_change)=digit_new;

その他の回答 (0 件)

カテゴリ

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

タグ

質問済み:

2020 年 12 月 22 日

回答済み:

2020 年 12 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by