Extracting the numeric part from a cell

Hi everyone,
I have a column string in this format
"injection-0:94577)"
"injection-0:94578)"
"injection-0:94579)"
"injection-0:94580)"
"injection-0:94581)"
"injection-0:94582)"
"injection-0:94583)"
I want to extract the numeric part that starts with 9 like 94577 from roow one for instance. Can anyone help please? Thank you.

 Respuesta aceptada

Paul
Paul el 17 de Nov. de 2021
str = ["injection-0:94577)"
"injection-0:94578)"
"injection-0:94579)"
"injection-0:94580)"
"injection-0:94581)"
"injection-0:94582)"
"injection-0:94583)"]
str = 7×1 string array
"injection-0:94577)" "injection-0:94578)" "injection-0:94579)" "injection-0:94580)" "injection-0:94581)" "injection-0:94582)" "injection-0:94583)"
newstr = extractBefore(extractAfter(str,":"),")")
newstr = 7×1 string array
"94577" "94578" "94579" "94580" "94581" "94582" "94583"

3 comentarios

Mahdi Khademishamami
Mahdi Khademishamami el 17 de Nov. de 2021
Editada: Mahdi Khademishamami el 17 de Nov. de 2021
Thank you! What about converting the newstr to an array? Should I use str2num?
I would just use double()
str = ["injection-0:94577)"
"injection-0:94578)"
"injection-0:94579)"
"injection-0:94580)"
"injection-0:94581)"
"injection-0:94582)"
"injection-0:94583)"];
newstr = extractBefore(extractAfter(str,":"),")");
d = double(newstr)
d = 7×1
94577 94578 94579 94580 94581 94582 94583
Mahdi Khademishamami
Mahdi Khademishamami el 17 de Nov. de 2021
Thanks again!

Iniciar sesión para comentar.

Más respuestas (1)

per isakson
per isakson el 17 de Nov. de 2021
Try
>> extractBetween( "injection-0:94582)", ":", ")" )
ans =
"94582"

Categorías

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

Etiquetas

Preguntada:

el 17 de Nov. de 2021

Comentada:

el 17 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by