How to extract only floating numbers from a string
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
parmeshwar prasad
am 20 Jun. 2018
Beantwortet: Riadh Essaadali
am 21 Mai 2023
Here is my string "21.5VgDC_0.05000V_VgAC_50M-150M30ms47GV1" How can I extract only the numbers 21.5, 0.05000, 50, 150 30 and 47 from the string. Thanks in advance
1 Kommentar
Akzeptierte Antwort
Stephen23
am 20 Jun. 2018
>> S = '21.5VgDC_0.05000V_VgAC_50M-150M30ms47GV1';
>> C = regexp(S,'\d+\.?\d*','match');
>> C{:}
ans = 21.5
ans = 0.05000
ans = 50
ans = 150
ans = 30
ans = 47
ans = 1
3 Kommentare
Walter Roberson
am 9 Mär. 2022
In the first one everything is optional, so it matches the empty pattern too.
The second one does require at least one digit. However it does not support digits followed by a decimal point with no digits after
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!