Question: Using Matlab I wrote this code for these instructions below. It it not working properly. It keeps getting stuck in an infinte loop. Please help.

Using Matlab I wrote this code for these instructions below. It it not working properly. It keeps getting stuck in an infinte loop. Please help. We are only suppose to use while loops and if statements to get this to work. For loops are not allowed.

Instructions:

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.

Here is my code below:

clear

clc

User=input('Enter a 1x5 vector []');

[r,c]=size(User);

while r~=1 && c~=5

i=0;

User=input('Enter a 1x5 vector []');

i=i+1;

if i==3

error('You have entered the incorrect size 3 times')

end

if r==5 && c==1

warning('You have entered a 5x1 vector')

User=User.';

end

end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!