Extract Numbers from a String
5 ビュー (過去 30 日間)
古いコメントを表示
Matthew Brandsema
2014 年 11 月 23 日
編集済み: Matthew Brandsema
2014 年 11 月 23 日
I have the following string from an excel file.
f 27//1 29//2 5//3 2//4
I want to extract the first number before each // sign. So for example, in this case, I need to extract the numbers 27 29 5 2
I am looking up how to do but but cannot seem to find a straightforward way, would anyone be able to clear things up for me? Thanks!
0 件のコメント
採用された回答
Azzi Abdelmalek
2014 年 11 月 23 日
a='f 27//1 29//2 5//3 2//4'
b=str2double(regexp(a,'\S+(?=//)','match'))
2 件のコメント
その他の回答 (1 件)
the cyclist
2014 年 11 月 23 日
編集済み: the cyclist
2014 年 11 月 23 日
You want the regexp command. For example,
s = 'f 27//1 29//2 5//3 2//4'
regexp(s,'//')
ans =
5 11 16 21
finds the positions of the //.
You could similarly find the positions of the spaces, and the numbers you want are between them.
You may then need to use str2num (or similar command) to convert the strings to numeric variables.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で String Parsing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!