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

1 vue (au cours des 30 derniers jours)
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]

Réponse acceptée

Stephen23
Stephen23 le 12 Jan 2022
Modifié(e) : Stephen23 le 12 Jan 2022
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

Plus de réponses (1)

Saeid
Saeid le 12 Jan 2022
Thank you both!

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by