How to randomly change a digit in a string

1 次查看(过去 30 天)
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
string1 = '00101';
digit_change = randi(length(string1));
digit_val = str2num(string1(digit_change));
digit_new = num2str(~digit_val);
string1(digit_change)=digit_new;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by