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

 Respuesta aceptada

Joseph Wilson
Joseph Wilson el 22 de Dic. de 2020

0 votos

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

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 22 de Dic. de 2020

Respondida:

el 22 de Dic. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by