I just dont know how to start What would be a good approach
I just don\'t know how to start. What would be a good approach?
Topics: User Defined Functions and MATLAB Conditionals
A mathematician needs you to write a MATLAB Function to verify the format of a floating point number input. A valid floating point number has the following properties:
Consists of at least 2 characters
Consists of only / exactly the following characters: +, -, . (decimal point), and 0 through 9
Either the + or - character may appear only as the first character
The . (decimal point) character must appear exactly once
All other characters must be a 0, 1, 2, 3, 4, 5, 6, 7, 8 or 9 character
Outline:
Create a MATLAB Function .m file
Establish its name (validate), input (a String), and output (the logical value true or false)
Write the necessary MATLAB commands to determine the correct result, using the given input
Return the result, by assigning the output variable
Make sure to test your function when it is done
You really need to write a separate Script file to do this properly / conveniently
Notes(s):
You will need to use the
= input(, \'s\');
version of input to read in and assign the non-evaluated string that the user types.
Your function must not display anything to the screen, nor get any user input.
Your function will simply return true or false based on the validity of its input.
Your function may not use the find() function or functions not introduced in lecture.
You are limited to \"for, while, if,else, elseif, break, return\"
Sample Run(s):
Please enter a valid floating pt literal : 0.
0. is a valid floating pt literal
Please enter a valid floating pt literal : .0
.0 is a valid floating pt literal
Please enter a valid floating pt literal : 1234
1245 is not a valid floating pt literal
Please enter a valid floating pt literal : 123.4
123.4 is a valid floating pt literal
Please enter a valid floating pt literal : 1234567.89
1234567.89 is a valid floating pt literal
Please enter a valid floating pt literal : -123.4
-123.4 is a valid floating pt literal
Please enter a valid floating pt literal : 1+23.4
1+23.4 is not a valid floating pt literal
Solution
updating soon
I just don\'t know how to start. What would be a good approach?
Topics: User Defined Functions and MATLAB Conditionals
A mathematician needs you to write a MATLAB Function to verify the format of a floating point number input. A valid floating point number has the following properties:
Consists of at least 2 characters
Consists of only / exactly the following characters: +, -, . (decimal point), and 0 through 9
Either the + or - character may appear only as the first character
The . (decimal point) character must appear exactly once
All other characters must be a 0, 1, 2, 3, 4, 5, 6, 7, 8 or 9 character
Outline:
Create a MATLAB Function .m file
Establish its name (validate), input (a String), and output (the logical value true or false)
Write the necessary MATLAB commands to determine the correct result, using the given input
Return the result, by assigning the output variable
Make sure to test your function when it is done
You really need to write a separate Script file to do this properly / conveniently
Notes(s):
You will need to use the
= input(, \'s\');
version of input to read in and assign the non-evaluated string that the user types.
Your function must not display anything to the screen, nor get any user input.
Your function will simply return true or false based on the validity of its input.
Your function may not use the find() function or functions not introduced in lecture.
You are limited to \"for, while, if,else, elseif, break, return\"


