Use the input( ) function to get the user input. Use the optional 's' argument to get the input as a char string.
I'm assuming you can use the ASCII table provided to decide what range a character is in. Note that numbers and letters are in contiguous sections, which allows you to do the following:
Suppose you have stored the user input in a variable called vname. Then
vname(1) >='A' && vname(1) <= 'Z'
would check to see if the first character is an uppercase letter.
vname(1) >='a' && vname(1) <= 'z'
would check to see if the first character is a lowercase letter.
vname(1) >='0' && vname(1) <= '9'
would check to see if the first character is a decimal digit.
would check to see if the first character is an underscore
Etc.
See if you can write some looping code based on the number of characters in vname to check all of this.
4 Comments
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652648-please-help-with-work#comment_1144463
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652648-please-help-with-work#comment_1144463
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652648-please-help-with-work#comment_1144488
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652648-please-help-with-work#comment_1144488
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652648-please-help-with-work#comment_1144513
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652648-please-help-with-work#comment_1144513
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652648-please-help-with-work#comment_1147539
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652648-please-help-with-work#comment_1147539
Sign in to comment.