How can I return an error in a loop format if user does not enter inputs in an array format?
Mostrar comentarios más antiguos
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?

Respuestas (1)
Walter Roberson
el 19 de Sept. de 2022
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.
Categorías
Más información sobre Entering Commands en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!