Write a MATLAB script (Classic program) that: Prompts it user to enter a valid I
ID: 3686263 • Letter: W
Question
Write a MATLAB script (Classic program) that: Prompts it user to enter a valid Integer literal Reads what the user types (unevaluated into a string variable Determines if the string is a valid Integer literal based on the following rules: Consists of only of the following characters: '+', "" and the digits '0' through '9' The '+' or '-' character may only appear (once) as the first character Consists of at least I character other than the characters: '+' or '-' character Display what the user entered and the determination to the screen in a reasonable report like formatExplanation / Answer
a)prompts the user to enter a valid integer literal
ans) command program for the above
b)matlab read what the user type into a string variable
Reading Strings
By default, the input function expects to read a number, and if the user types: hello it will assume that hello is a variable containing a number. If you really want the string "hello" then you would have to type 'hello' (tick marks).
To tell a Matlab program to read a string of characters directly with out having to type the tick marks, you must use the 's' syntax as shown here:
c)
x = input(prompt)
str = input(prompt,'s')
startIndex = regexp(str,expression) returns the starting index of each substring of str that matches the character patterns specified by the regular expression. If there are no matches, startIndex is an empty array.
[startIndex,endIndex] = regexp(str,expression) returns the starting and ending indices of all matches
d)display what the user enter and determination to the screen reasonable report like formate
format style changes the output display format in the Command Window to the format specified by style.
format, by itself, resets the output format to the default, which is the short, fixed-decimal format for floating-point notation and loose line spacing for all output lines.
Numeric formats affect only how numbers appear in Command Window output
Examples:
Long Format
Open This Example
Set the output format to the long fixed-decimal format and display the value of pi.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.