How to check if a string contains only numbers?
조회 수: 241 (최근 30일)
이전 댓글 표시
Is there any expression for this ? For example :
-100 should return 1
a100b should return 0
0.1256 should return 1 and so on
댓글 수: 0
채택된 답변
Walter Roberson
2017년 12월 14일
The easiest way is to check if str2double() returns nan. Otherwise you need to parse the string and there are a number of odd cases to account for in scientific notation.
Note: if you do use str2double() you should give some consideration as to what result you want for complex numbers, whether those are to be treated as numeric or as invalid because of the 'i' or 'j' present.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!