find numbers in a string
Afficher commentaires plus anciens
Hi,
I have the following example of string 'E_Field (Farfield) (Cartesian) (-0 -1000 -1)(Abs) (cosim Tran1).txt' .
I need to extract the numbers between the brackets 0,1000,-1.
I have tried using the regexp function but without any success.
I will appriciate any kind of assistance.
Réponses (1)
s = 'E_Field (Farfield) (Cartesian) (-0 -173.648 983.808)(Abs) (cosim Tran1).txt';
s1 = 'E_Field (Farfield) (Cartesian) (-0 -1000 -1)(Abs) (cosim Tran1).txt' ;
p = '(\(-?\d+ -?\d+(.\d*)? -?\d+(.\d*)?\))';
t=regexp(s, p, 'tokens');
t = t{1}{1}
n = sscanf(t, '(%f %f %f)')
t1=regexp(s1, p, 'tokens');
t1 = t1{1}{1}
n1 = sscanf(t1, '(%f %f %f)')
5 commentaires
EYAL COHEN
le 25 Juil 2023
Chunru
le 25 Juil 2023
See the updated.
EYAL COHEN
le 25 Juil 2023
Chunru
le 25 Juil 2023
See above
EYAL COHEN
le 25 Juil 2023
Déplacé(e) : Bruno Luong
le 25 Juil 2023
Catégories
En savoir plus sur Cell Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!