Question

In: Computer Science

In MatLab 1. Ask the user to enter a 1 x 5 vector of numbers. Determine...

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.

Solutions

Expert Solution

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


Related Solutions

I need to ask a user what numbers they want to enter. They can enter as...
I need to ask a user what numbers they want to enter. They can enter as many as they like. Then inside I need to use conditionals to determine if the numbers are <=20, <=323 && > 30, >200. I can't figure out how to let the user enter as many inputs as they want. I know I need to use a loop to check each number entered and determine if it is small middle or greater but I can't...
Implement the working of a mohr circle in matlab. ask user to enter the stresses in...
Implement the working of a mohr circle in matlab. ask user to enter the stresses in x and y direction. take the inputs to a stress tensor. then use formulations to find the eigen value and vectors. MATLAB
Write a MIPS program that will ask the user to enter two numbers at the console...
Write a MIPS program that will ask the user to enter two numbers at the console and pass the values to a function that does multiplication
C++ Programa that: // 1) Ask the user to enter two numbers greater than zero. Store...
C++ Programa that: // 1) Ask the user to enter two numbers greater than zero. Store the //    values into two variables named 'n' and 'm'. //    Additionally, implement a while-loop to keep asking the user to enter //    the numbers again if any of the two numbers are equal or smaller than zero. // 2) If the two numbers (n, m) are equal, display the message "The //    numbers are the same". If the two numbers are different, display...
for python 3 a. Ask the user to enter 10 numbers. Each number is stored in...
for python 3 a. Ask the user to enter 10 numbers. Each number is stored in a list called myList. Compute and print out the sum and average of the items in the list. Print the numbers that are divisible by 2 from myList. b. Instead of using a list to store the numbers, create a loop to accept the numbers from the user, and find the average of all the numbers. Hint: use an accumulator to store the numbers...
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The...
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The program will use a while loop to let the program keep running. The user will be allowed to use the program as long as the quitVariable is equal to 'y' or 'Y'. When the user decides to quit playing, say "Thanks for playing!". The program will use a for loop to test if the number are even or odd. If even print "number is...
Use a for loop to ask a user to enter the grades of 5 courses. The...
Use a for loop to ask a user to enter the grades of 5 courses. The user should enter character values, e.g., A. Calculate the GPA of the user Hint: Convert the character values entered to numerals, e.g., A to 4 c programming help me please
C++ Bubble Sort Write a program that ask user to enter 7 numbers and store that...
C++ Bubble Sort Write a program that ask user to enter 7 numbers and store that in array. Display that all numbers before and after performing Bubble sort. You must have to create new function with required parameter to perform Bubble sort. Sample Run :- Enter 1 number :- 1 Enter 2 number :- 5 Enter 3 number :- 7 Enter 4 number :- 45 Enter 5 number :- 90 Enter 6 number :- 6 Enter 7 number :- 55...
1. Write a program that will ask the user to enter a character and then classify...
1. Write a program that will ask the user to enter a character and then classify the character as one of the following using only IF-ELSE and logical operators. (50 points - 10pts for syntax, 10pts for commenting and 30pts for successful execution) • Integer • Lower Case Vowel • Upper Case Vowel • Lower Case Consonant • Upper Case Consonant • Special Character
Write a C++ code to ask the user to enter 4 values (whole numbers). Your code...
Write a C++ code to ask the user to enter 4 values (whole numbers). Your code should print the numbers in descending order.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT