How to split a string and return only decimal numbers?

20 ビュー (過去 30 日間)
K E
K E 2015 年 2 月 25 日
コメント済み: K E 2015 年 2 月 25 日
I would like to extract a vector x containing decimal numbers from this string,
myString = 'YYYY MM DD hh mm .0200 .0325 .0375 .0425 .0475 .0525 .0575 .0625 .0675';
x = [.0200 .0325 .0375 .0425 .0475 .0525 .0575 .0625 .0675]
I have been able to split myString on the white spaces as follows,
splitstring = regexp(myString,'\s+','split');
% 'YYYY' 'MM' 'DD' 'hh' 'mm' '.0200' '.0325' '.0375'
but this doesn't exclude the "words" at the start. Using '\s+[^a-zA-Z]' or '\s+[0-9]' won't return the decimal numbers either.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 2 月 25 日
編集済み: Azzi Abdelmalek 2015 年 2 月 25 日
myString = 'YYYY MM DD hh mm .0200 .0325 .0375 .0425 .0475 .0525 .0575 .0625 .0675';
out=regexp(myString,'\d?\.?\d+','match')
  1 件のコメント
K E
K E 2015 年 2 月 25 日
Thanks! Never can get these right.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by