Extracting numbers from non-formatted text
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have a non-formatted text file from which all those numbers need to be extracted which are exactly 10-digit numbers.
Here is the short version of the file :
*()%
kpm c)ompany
1234567890
freight carrier 56789
62345
roadway&s 3456781910
invoice STW7228
5. HRM Ï4
gate \ *+*
3498712338 1 2765114
3790000155678 f ^
4462213459 \
The file is txt and is non-formatted. Formating is not needed. Only value of interest are the 10-digit numbers.
How can this be done ?
0 commentaires
Réponse acceptée
Ameer Hamza
le 17 Mai 2020
Try this
str = fileread('test.txt'); % test.txt is the name of text file containing the given text
matches = regexp(str, '\d{10}', 'match')
Result
>> matches
matches =
1×5 cell array
Columns 1 through 4
{'1234567890'} {'3456781910'} {'3498712338'} {'3790000155'}
Column 5
{'4462213459'}
2 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!