Identifying numbers within a long string containing multiple occurrences of text and numbers in one row

조회 수: 1 (최근 30일)
Read from a text file, my input array contains one row that looks like this:
x y z p (Pa) @ mDot=0.003 p (Pa) @ mDot=0.03 p (Pa) @ mDot=0.3 p (Pa) @ mDot=3
Is there a way to identify the numbers in that row and create a separate numerical array based on them?
Something like:
NUMM=[0.003 0.03 0.3 3]

채택된 답변

Stephen23
Stephen23 2022년 1월 12일
편집: Stephen23 2022년 1월 12일
Simpler and gives the requested output:
str = 'x y z p (Pa) @ mDot=0.003 p (Pa) @ mDot=0.03 p (Pa) @ mDot=0.3 p (Pa) @ mDot=3';
out = str2double(regexp(str,'\d+\.?\d*','match'))
out = 1×4
0.0030 0.0300 0.3000 3.0000

추가 답변 (1개)

Saeid
Saeid 2022년 1월 12일
Thank you both!

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by