Extracting numbers from non-formatted text

1 vue (au cours des 30 derniers jours)
b
b le 17 Mai 2020
Commenté : Ameer Hamza le 18 Mai 2020
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 ?

Réponse acceptée

Ameer Hamza
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
b
b le 18 Mai 2020
Thanks.
Ameer Hamza
Ameer Hamza le 18 Mai 2020
I am glad to be of help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Code Generation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by