How to extract numbers from a string?

26 visualizaciones (últimos 30 días)
John Doe
John Doe el 12 de Jul. de 2020
Comentada: John Doe el 12 de Jul. de 2020
xx = '[10,10]'
I want to convert the string xx to a number and extract the first and second value in a single line. What I am trying to do is extract the 1st and 2nd value without storing them in any variable.
Is there any solution to this? Thanks!

Respuesta aceptada

madhan ravi
madhan ravi el 12 de Jul. de 2020
Editada: madhan ravi el 12 de Jul. de 2020
sscanf(xx, '[%d, %d]', [1,inf])
%or
str2double(regexp(xx, '\d*', 'match'))
  3 comentarios
madhan ravi
madhan ravi el 12 de Jul. de 2020
Rather complicated:
subsref(str2double(regexp(xx,'\d*','match')), substruct('()', {2}))
John Doe
John Doe el 12 de Jul. de 2020
Thanks! My day is saved!

Iniciar sesión para comentar.

Más respuestas (0)

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!

Translated by