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

in MIPS assembly, ask a user for two numbers and to either enter a '1' for...
in MIPS assembly, ask a user for two numbers and to either enter a '1' for addition or '2' for subtraction. using jal, jump to the appropriate procedure for additing or subtracting. then print out result and ask if there is another calculation (terminate program if 'no').
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
In MIPS assembly: Ask the user to enter two numbers and an operation (+ - /...
In MIPS assembly: Ask the user to enter two numbers and an operation (+ - / *). Print the expression back to the user with a blank after the = sign (since the calculation is not being completed.  
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
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 compute xy
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...
using MIPs assembly, ask the user to enter two numbers. Then multiply the two numbers using...
using MIPs assembly, ask the user to enter two numbers. Then multiply the two numbers using bit shifting (not 'mul'). This should work multiplying 2 positive numbers, 2 negative numbers, and a positive/negative number. Then output the result and ask user if he/she has more calculations to complete.
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
5) Write a JavaScript script that will ask the user to enter in the length of...
5) Write a JavaScript script that will ask the user to enter in the length of the side of a cube. (all the sides of a cube are equal) Based on the value that is entered by the user from the keyboard, calculate each of the following and assign your results to variables. 1. volume of the cube 2. surface area of the cube 3. volume of the largest sphere that could fit in the box. 4. surface area of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT