Identify a number in a string
8 次查看(过去 30 天)
显示 更早的评论
Hi all, I would like to know how to identify and extract a number or digit from a string or text, so if I have Ans = ['2.66 meters in the front of the mirror']; I would only like to identify and extract the double, this should be a general thing and not only specific to the 2.66. Please help
0 个评论
采纳的回答
更多回答(1 个)
Ameer Hamza
2020-10-11
编辑:Ameer Hamza
2020-10-11
Try sscanf()
str = '2.66 meters in the front of the mirror';
nums = sscanf(str, '%f');
Result
>> nums
nums =
2.6600
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!