Extracting a number from a sentence string
Ältere Kommentare anzeigen
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.
Antworten (1)
per isakson
am 8 Feb. 2015
Bearbeitet: per isakson
am 8 Feb. 2015
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' :-(
Kategorien
Mehr zu String Parsing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!