- #1
gfd43tg
Gold Member
- 950
- 50
Homework Statement
Often times, a program accepts input from a user, and needs to check the validity of the input, and
then produce useful and informative error messages if the input is invalid. Suppose that uiVal is a
variable representing the user's input, and that errorCode is an 1-by-0 empty array. Write Matlab
code that appends to errorCode various identifying integers depending on certain conditions as
follows:
1, if uiVal is not a numeric, real-valued array
2, if uiVal is not all integer valued. Note that if uiVal is not numeric, real-valued (as is
checked in the rst item) then this condition should not be checked, since it may produce
an error.
3, if any values of uiVal are less than 1 or greater than 6. Note that if uiVal is not numeric,
real-valued (as is checked in the rst item) then this condition should not be checked, since
it may produce an error.
4, if uiVal is not 2-dimensional (use command ndims) or it's size is not equal to 1-by-4.
Homework Equations
The Attempt at a Solution
Right now my code is getting 4/7, I can't figure out what is wrong. Everything seems fine in the code, but when I run uiVal = @sign it gives errorCode = [1 1]
Code:
errorCode = zeros(1,0);
if ~(isnumeric(uiVal) && isreal(uiVal))
errorCode = [errorCode, 1];
else
if (uiVal ~= round(uiVal))
errorCode = [errorCode, 2];
end
if (any(uiVal < 1) | any(uiVal > 6))
errorCode = [errorCode, 3];
end
end
if ndims(uiVal)~= 2 | size(uiVal) ~= [1,4]
errorCode = [errorCode, 4];
end
This is the autograder remarks:
Code:
Problem 3: 4/7
*the value of errorCode is incorrect for the variables: uiVal = '[1 2 3 4]';
The size of your variable is not as expected
*the value of errorCode is incorrect for the variables: uiVal = [1 2 3 4 5];
The size of your variable is not as expected
*the value of errorCode is incorrect for the variables: uiVal = @sign;
The size of your variable is not as expected
Last edited: