Extract two floating point numbers from a string
显示 更早的评论
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.
采纳的回答
更多回答(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')
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!