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

Illustration of customizing plots, Illustration of Customizing plots: ...

Illustration of Customizing plots: Illustration, the bar and barh functions by the default place a width of 0.8 between bars. Whenever called as bar(x,y), the width of 0.8 is

Example of function stubs, Example of Function stubs: The three functi...

Example of Function stubs: The three functions have not so far been written, though, therefore the function stubs are put in place so that the script can be executed and teste

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

Illustrations of sequential search, Illustrations of Sequential search: ...

Illustrations of Sequential search: The two illustrations of calling such function is as shown below: >> values = [85 70 100 95 80 91]; >> key = 95; >> seqsearch

Program of persistent variables, Program of Persistent variables: The ...

Program of Persistent variables: The program below elaborates this. The script calls a function func1 that initializes a variable count to 0, then increment it, and print the

Representing logical true and false, Representing Logical true and False: ...

Representing Logical true and False: It has been stated that expressions which are theoretically true really have the integer value of 1, and expressions which are theoretical

Roots function - polynomials, Roots function - Polynomials: The roots ...

Roots function - Polynomials: The roots function in MATLAB is used to find the roots of an equation represented by a polynomial. For illustration, for the mathematical functio

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

Example of median, Example of Median For the vector [1 4 5 9 12 33], th...

Example of Median For the vector [1 4 5 9 12 33], the median is the average of the 5 & 9 in the middle: >> median([1 4 5 9 12 33]) ans =     7

Illustration of median, Illustration of Median When the vector is not i...

Illustration of Median When the vector is not in sorted order to start with, the median function will still return the right answer (it will sort the vector automatically). For

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