How to extract values from a string.
15 ビュー (過去 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!