How to randomly change a digit in a string
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dani Niwa
le 22 Déc 2020
Réponse apportée : Joseph Wilson
le 22 Déc 2020
I have a string = 00101 How i can randomly change one digits of that string? Ex: 00101=>00100
0 commentaires
Réponse acceptée
Joseph Wilson
le 22 Déc 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!