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!