How can I return an error in a loop format if user does not enter inputs in an array format?
이전 댓글 표시
I want to ask for error message if user inputs are not entered in a array format. Code is attached below. Please how do I do this?

답변 (1개)
Walter Roberson
2022년 9월 19일
use the input option 's' to receive the characters the user entered. Check to be sure that the characters entered match the syntaxes you wish to permit such as requiring that it be of the format
optional whitespace
[
optional whitespace
one or more decimal digits
optional whitespace
comma
optional whitespace
one or more decimal digits
optional whitespace
]
optional whitespace
This check is easy to do using regexp()
Then convert the sequences of digits from characters to numeric
This assumes that you wish to enforce that they use a comma between the parts, refusing (for example) [2 8] for not being in the form you instruct because it does not have the comma.
카테고리
도움말 센터 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!