Extracting a number from a sentence string
이전 댓글 표시
I am trying to extract numbers from a sentence string through a function that does not know the exact placement or how many numbers are in the string.
for example my input would be
a='my weight is between 200 and 250 lbs'
or it could be
a='my weight is 200 lbs'
the weight will always be before "lbs", but the length of weight string is unknown.
I am having trouble using the sscanf function to make a universal code to extract the numbers from a string. Any help is greatly appreciated.
답변 (1개)
per isakson
2015년 2월 8일
편집: per isakson
2015년 2월 8일
A start
>> a='my weight is between 200 and 250 lbs'
a =
my weight is between 200 and 250 lbs
>> cac = regexp( a, '\d++', 'match' )
cac =
'200' '250'
Warning: This will not match '1.2E-003', not even '-4' :-(
카테고리
도움말 센터 및 File Exchange에서 String Parsing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!