MATLAB Answers

How to extract numbers from a string?

13 views (last 30 days)
John Doe
John Doe on 12 Jul 2020
Commented: John Doe on 12 Jul 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!

Accepted Answer

madhan ravi
madhan ravi on 12 Jul 2020
Edited: madhan ravi on 12 Jul 2020
sscanf(xx, '[%d, %d]', [1,inf])
%or
str2double(regexp(xx, '\d*', 'match'))
  3 Comments
John Doe
John Doe on 12 Jul 2020
Thanks! My day is saved!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!