Identify a number in a string
34 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Omphemetse Moeng
am 11 Okt. 2020
Kommentiert: Omphemetse Moeng
am 11 Okt. 2020
Hi all, I would like to know how to identify and extract a number or digit from a string or text, so if I have Ans = ['2.66 meters in the front of the mirror']; I would only like to identify and extract the double, this should be a general thing and not only specific to the 2.66. Please help
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Ameer Hamza
am 11 Okt. 2020
Bearbeitet: Ameer Hamza
am 11 Okt. 2020
Try sscanf()
str = '2.66 meters in the front of the mirror';
nums = sscanf(str, '%f');
Result
>> nums
nums =
2.6600
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!