How to extract numbers from a string?

35 vues (au cours des 30 derniers jours)
John Doe
John Doe le 12 Juil 2020
Commenté : John Doe le 12 Juil 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!

Réponse acceptée

madhan ravi
madhan ravi le 12 Juil 2020
Modifié(e) : madhan ravi le 12 Juil 2020
sscanf(xx, '[%d, %d]', [1,inf])
%or
str2double(regexp(xx, '\d*', 'match'))
  3 commentaires
madhan ravi
madhan ravi le 12 Juil 2020
Rather complicated:
subsref(str2double(regexp(xx,'\d*','match')), substruct('()', {2}))
John Doe
John Doe le 12 Juil 2020
Thanks! My day is saved!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by