How to randomly change a digit in a string
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Dani Niwa
am 22 Dez. 2020
Beantwortet: Joseph Wilson
am 22 Dez. 2020
I have a string = 00101 How i can randomly change one digits of that string? Ex: 00101=>00100
0 Kommentare
Akzeptierte Antwort
Joseph Wilson
am 22 Dez. 2020
string1 = '00101';
digit_change = randi(length(string1));
digit_val = str2num(string1(digit_change));
digit_new = num2str(~digit_val);
string1(digit_change)=digit_new;
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!