How to split a string and return only decimal numbers?

조회 수: 21 (최근 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')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by