How to extract values from a string.
17 次查看(过去 30 天)
显示 更早的评论
So I have a string in the following format:
filename = "Delft_2_220_20_4344-5088.csv" ;
And I want to extract the numbers from it, what is a good way to do this?
So the result is something like this:
a=2; b=220; c=20;d=[4344 5088];
采纳的回答
Stephen23
2019-5-24
编辑:Stephen23
2019-5-24
>> S = 'Delft_2_220_20_4344-5088.csv';
>> V = str2double(regexp(S,'\d+','match'))
V =
2 220 20 4344 5088
Using indexing to allocate those values to whatever other variables you want.
2 个评论
madhan ravi
2019-5-24
编辑:madhan ravi
2019-5-24
+1 Stephen, also if the string contains decimals then
regexp(s,'\d+[\.]?\d*','match')
更多回答(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!