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
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

Nested Structures: The nested structure is a structure in which at least one of the members is itself a structure. For illustration, a structure for the line segment may co

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

Indexing: The Indexing is an alternate to sort a vector. With indexing, the vector is left in its original order. An index vector is used to point values in the original vecto

Example of Core objects: The one core graphics object is a line that is also what the plot function produces. Here is an illustration of generating a line object, altering som

Sorting Strings: For the matrix of strings, the sort function works exactly as formerly for numbers. For illustration, >> words = char('Hi', 'Hello', 'Howdy', 'Goodbye', '

Variable packages: Variable packages are now the vector of structures, hence each and every element in the vector is a structure. To show one element in the vector, an index i

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

Mode The mode of a data set is the value which appears most often. The built-in function in a MATLAB for this is known as the mode. >> x = [9 10 10 9 8 7 3 10 9 8 5 10];

Logical Built-In Functions: There are built-in functions in the MATLAB which are useful in conjunction with vectors or matrices of all logical true or false values; two of the