Extract two floating point numbers from a string
Show older comments
This should be easy, but I have no experience with MATLAB regexp or pattern and can't adapt the other answers about extracting numbers from a mixed string.
I want to get the latitude and longitude as floating point numbers from a string that looks like this:
23.047°S 67.782°W
The numbers will have 1-3 characters before the decimal point. An "S" or a "W" will produce a negative number.
Suggestions welcome.
Accepted Answer
More Answers (1)
T = '23.047°S 67.782°W 9.876°N 5.432°E' ;
V = sscanf(regexprep(T,{'(\S+)°[SW]','(\S+)°[NE]'},{'-$1','+$1'}),'%f')
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!