filter string in the string
Afficher commentaires plus anciens
Hello,
I am quietly new with matlab script.
I have a string as example.
str = 'this matlab is a good software, it is a version 9.4 which is equal to 2018a'
objective, I want to filter the number from that string ( so it is "9.4").
Note that I cannot see that number. All i want is to scan that number and show in my workspace.
so the scribt should read the text and identify the number of the version and show in my workspace.
I appreciate your help.
Regards,
LN
2 commentaires
Ted Shultz
le 21 Août 2019
Do you not want to also get '2018'? What rule would the code use to exclude this?
Adam
le 21 Août 2019
doc regexp
should help do this. It takes a bit of getting used to parameterising regular expressions though. There are likely simpler ways depending how robust you want it to be.
Réponse acceptée
Plus de réponses (2)
>> str = 'this matlab is a good software, it is a version 9.4 which is equal to 2018a';
>> out = regexp(str,'\d+\.\d+','match','once')
out = 9.4
1 commentaire
Liger
le 28 Août 2019
Using a regular expression:
numbers = regexp(youstring, '\<\d*\.?\d+\>', 'once')
which will extract any number not attached to text. Allowed formats for number is 123, 123.45, .123
Catégories
En savoir plus sur Data Type Identification 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!