How to extract numbers from a string?
26 次查看(过去 30 天)
显示 更早的评论
xx = '[10,10]'
I want to convert the string xx to a number and extract the first and second value in a single line. What I am trying to do is extract the 1st and 2nd value without storing them in any variable.
Is there any solution to this? Thanks!
0 个评论
采纳的回答
madhan ravi
2020-7-12
编辑:madhan ravi
2020-7-12
sscanf(xx, '[%d, %d]', [1,inf])
%or
str2double(regexp(xx, '\d*', 'match'))
3 个评论
madhan ravi
2020-7-12
Rather complicated:
subsref(str2double(regexp(xx,'\d*','match')), substruct('()', {2}))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!