How to extract numbers from a string?

35 ビュー (過去 30 日間)
John Doe
John Doe 2020 年 7 月 12 日
コメント済み: John Doe 2020 年 7 月 12 日
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!

採用された回答

madhan ravi
madhan ravi 2020 年 7 月 12 日
編集済み: madhan ravi 2020 年 7 月 12 日
sscanf(xx, '[%d, %d]', [1,inf])
%or
str2double(regexp(xx, '\d*', 'match'))
  3 件のコメント
madhan ravi
madhan ravi 2020 年 7 月 12 日
Rather complicated:
subsref(str2double(regexp(xx,'\d*','match')), substruct('()', {2}))
John Doe
John Doe 2020 年 7 月 12 日
Thanks! My day is saved!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by