Separating numbers and characters from input

11 visualizaciones (últimos 30 días)
Valeria Chacon
Valeria Chacon el 25 de Oct. de 2016
Comentada: Andrei Bobrov el 26 de Oct. de 2016
If a user inputs a random amount of characters For example: str=input(prompt,'s'); and they input: 123wd57ab934bd3 how can I separate the numbers and the characters? Thank you!

Respuestas (1)

Andrei Bobrov
Andrei Bobrov el 25 de Oct. de 2016
str = '123wd57ab934bd3';
z = regexp(str,'(\d*)([a-z]*)','tokens');
out = [z{:}];
out = out(~cellfun(@isempty,out));
  3 comentarios
Valeria Chacon
Valeria Chacon el 25 de Oct. de 2016
is there any way that I could pull out the numbers? maybe even one by one? so instead of separating I get only the numbers.
Andrei Bobrov
Andrei Bobrov el 26 de Oct. de 2016
str = '123wd57ab934bd3';
z = str2double(regexp(str,'\d*','match'));

Iniciar sesión para comentar.

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by