Delete iterations in a string of numbers
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
majed majed
el 19 de Mzo. de 2016
Ho are you everyone !
I have this string :
S=[222223444451111122666677775555533332222], if I want to delete the iterations in this string to get the string :
ss=[2 3 4 5 1 2 6 7 5 3 2], what is the proper function for this purpose? Thank you a lot for any answer
1 comentario
Jan
el 19 de Mzo. de 2016
To be exact: Do you mean:
S = '222223444451111122666677775555533332222'
and
ss = '23451267532'
Which types have S and ss?
Respuesta aceptada
Stephen23
el 19 de Mzo. de 2016
Editada: Stephen23
el 19 de Mzo. de 2016
Remove repetitions, return a string:
>> str = '222223444451111122666677775555533332222';
>> new = str([true,diff(+str)~=0])
new =
23451267532
It is easy to convert the string into a numeric vector of the digits:
>> vec = new-'0'
vec =
2 3 4 5 1 2 6 7 5 3 2
1 comentario
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!