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!

 Akzeptierte Antwort

madhan ravi
madhan ravi am 12 Jul. 2020
Bearbeitet: madhan ravi am 12 Jul. 2020

1 Stimme

sscanf(xx, '[%d, %d]', [1,inf])
%or
str2double(regexp(xx, '\d*', 'match'))

3 Kommentare

John Doe
John Doe am 12 Jul. 2020
Bearbeitet: John Doe am 12 Jul. 2020
Thanks Madhan for the prompt reply.
Could you please tell me what to do if I want to extract the second value only from xx?
Rather complicated:
subsref(str2double(regexp(xx,'\d*','match')), substruct('()', {2}))
John Doe
John Doe am 12 Jul. 2020
Thanks! My day is saved!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 12 Jul. 2020

Kommentiert:

am 12 Jul. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by