In: Computer Science
In MatLab
1. Ask the user to enter a 1 x 5 vector of numbers. Determine
the size of the user entry.
2. Ask the user to enter a 1 x 5 vector of numbers. Determine the
size of the user entry. If the user enters a 5 x 1 vector, use a
warning statement to inform the user of their error, and set the
new input value to be the transpose of the user input value. If the
user enters a vector that is not the correct size, use an error
message to terminate the program.
3. Ask the user to enter a 1 x 5 vector of numbers. Determine the
size of the user entry. If the user enters a 5 x 1 vector, use a
warning statement to inform the user of their error, and set the
new input value to be the transpose of the user input value. If the
user enters a vector that is not the correct size, ask the user to
re-enter the vector using the correct dimensions. The program
should continuously check the user input each time it is entered.
Continue to ask the user to input a new vector until the user
correctly enters a 1 x 5 vector.
4. Ask the user to enter a 1 x 5 vector of numbers. Determine the
size of the user entry. If the user enters a 5 x 1 vector, use a
warning statement to inform the user of their error, and set the
new input value to be the transpose of the user input value. If the
user enters a vector that is not the correct size, ask the user to
re-enter the vector using the correct dimensions. The program
should continuously check the user input each time it is entered.
Continue to ask the user to input a new vector until the user has
entered three tries. If the user fails to enter a vector correctly
given three chances (including the first entry), use an error
message to terminate the program.
tries = 0;
correct = false;
while tries < 3 && correct == false
v = input('Enter a 1x5 vector of numbers: ');
tries = tries + 1;
[m, n] = size(v);
if m == 1 && n == 5
correct = true;
elseif m == 5 && n == 1
warning('You entered a 5x1 vector.
Setting to transpose');
v = v';
correct = true;
else
disp('You entered an incorrect
dimension vector');
end
end
if correct == false
error('You did not enter a 1x5 vector in 3 attempts!
Terminating program.');
else
disp(v);
end
output
-----
Enter a 1x5 vector of numbers: > [2]
You entered an incorrect dimension vector
Enter a 1x5 vector of numbers: > [1 2]
You entered an incorrect dimension vector
Enter a 1x5 vector of numbers: > [1; 2; 3; 4; 5]
warning: You entered a 5x1 vector. Setting to transpose
warning: called from
warn at line 10 column 3
1 2 3 4 5