Input in a while loop, MATLAB in Statistics

Assignment Help:

Input in a While Loop:

The script below repeats the procedure of prompting a user, the reading in a positive number, and echo-printing it, as long as the user properly enters positive numbers whenever prompted. As soon as the user types in a negative number, the program will print the OK and end.

1318_Input in a While Loop.png

Whenever the program is executed, the input/output mayt look like this:

>> whileposnum

Enter a positive number: 6

You entered a 6.

Enter a positive number: -2

OK!

 

Whenever the user enters a negative number at the first time, no values will be echo-printed:

>> whileposnum

Enter a positive number: -33

OK!

 

This describes a very important feature of the while loops: it is possible that the action will not be executed at all, if the value of the condition is false at the first time it is computed.

As we have seen before, the MATLAB will give an error message when a character is entered instead of a number.

 

>> whileposnum

Enter a positive number: a

??? Error using ==> input

Undefined function or variable 'a'.

Enter a positive number: -4

OK!

 

Though, if the character is really the name of variable, it use the value of that variable as the input. For illustration:

>> a = 5;

>> whileposnum

Enter a positive number: a

You entered a 5.

Enter a positive number: -4

OK!



Related Discussions:- Input in a while loop

Statistics, Statistics There are numerous statistical analyses which ca...

Statistics There are numerous statistical analyses which can be executed on data sets. In MATLAB software, the statistical functions are in the data analysis help topic known a

Help function, Help function: Function is computing the two values, th...

Help function: Function is computing the two values, there are two output arguments in the function header (i.e., area & circum), that are placed in the square brackets [ ]. A

Bus311.., #qYou will need to examine two of the nine sections of data: one ...

#qYou will need to examine two of the nine sections of data: one section of qualitative data (choose either Gender or Position) one section of quantitative data (choose either Intr

Illustration of nested for loops and the if statements, Illustration of nes...

Illustration of nested for loops and the if statements: For illustration,when the file contains: 33   -11  2  4      5   9 22     5  -7  2     11    3 the outco

Input in a while loop, Input in a While Loop: The script below repeats...

Input in a While Loop: The script below repeats the procedure of prompting a user, the reading in a positive number, and echo-printing it, as long as the user properly enters

Illustration of binary search, Illustration of Binary search: An illus...

Illustration of Binary search: An illustration to search for the key of 91 in the vector is as shown below: The table below shows what will happen in each iteration of

Sequential search, Sequential Search: A sequential search is completed...

Sequential Search: A sequential search is completed by looping through the vector element-by-element starting from the beginning, looking for the key. Usually the index of the

Example of mode, Example of Mode When no value appears more often than ...

Example of Mode When no value appears more often than any other, the smallest value in the vector will be the mode of the vector. >> shortx = [2 5 1 4]; >> mode(shortx

Advanced file input and output, Advanced File Input and Output: In tha...

Advanced File Input and Output: In that section, we saw how to read the values entered by user using the input as well as the output functions disp and fprintf, that shows inf

Nested functions, Nested Functions: We have seen that the loops can be...

Nested Functions: We have seen that the loops can be nested, that means that one inside of the other, functions can be nested. The terminology for nested functions is that an

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd