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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by