Execution of persistent variables, MATLAB in Statistics

Execution of persistent variables:

The functions can also be called from the script or from the Command Window, as shown here. For illustration, the functions are called first from the script. With the persistent variable, value of count is incremented. Then, the func1 is called from Command Window, & func2 is also called from Command Window. As the value of the persistent variable had the value 2, at this time it is incremented to 3.

 

>> persistex

This is what occurs with a normal variable:

The value of count is 1

The value of count is 1

This is what occurs with a persistent variable:

The value of count is 1

The value of count is 2

>> func1

The value of count is 1

>> func2

The value of count is 3

 

As it can be seen here, that each and every time the function func1 is called, whether from the persistex or from Command Window, the value of 1 is printed. Though, with func2 the variable count is incremented each and every time it is called. It is first called in this illustration from persistex twice; therefore the count is 1 and then 2. Then, whenever called from the Command Window, it is incremented to 3. Obviously, the numbering of the error messages will carry on if the function is executed again.

 

Posted Date: 10/20/2012 4:16:42 AM | Location : United States







Related Discussions:- Execution of persistent variables, Assignment Help, Ask Question on Execution of persistent variables, Get Answer, Expert's Help, Execution of persistent variables Discussions

Write discussion on Execution of persistent variables
Your posts are moderated
Related Questions
Location of a rectangle - graphics objects: The location of a rectangle is [x y w h], where x and y are the coordinates of the lower left point, here w is the width, and h is

Illustration of tracing a error: The one way of following the flow of function, or tracing it, is to use the echo function. The echo function, that is a toggle, will show each

Areacirc function: The areacirc function can be called from the Command Window as shown here, or from a script. Here is a script which will prompt the user for the radius of o

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

Properties of the text box - graphics objects: By using get will show properties of the text box, the illustration is as shown below: >> get(thand)   BackgroundColor

Illustration of Mode When there is more than one value with similar (highest) frequency, then the smaller value is mode. In the case below, as 3 and 8 appear twice in the vecto

function sortrows - sorting strings: The function sortrows sorts each and every row as a block, or group, and it also will work on numbers. Here in this illustration the rows

Example of customizing plots: As the other illustration of customizing plots, the pieces of a pie chart can be "exploded" from the rest. In this situation, the two vectors are

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

bjjh