Edit user input
显示 更早的评论
Lets say i have something like s='12s+34a+45'; Is there a way so i can only store the numbers that are in front of the letter s and store it to an array?
采纳的回答
更多回答(1 个)
Raldi
2011-12-2
0 个投票
1 个评论
Walter Roberson
2011-12-2
If you define exactly which patterns of characters are to be accepted, then a regexp() expression can be constructed. The pattern to match a general floating point number that might be in exponential form gets quite complicated though.
numstrs = regexp(TheString, '-?(?:(?:\d*\.)?\d+|\d+\.)(?=\s*s)', 'match')
The above does not recognize exponentials, but it does recognize
optional leading minus sign, recognizes digits followed by 's', recognizes digits followed by '.s', recognizes digits followed by '.' followed by digits followed by 's', recognizes '.' followed by digits followed by 's', while still refusing '.s' alone with no digits. Oh yes, optional spaces are permitted before the 's' itself.
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!