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
Function Stubs: The other common debugging method, which is used when there is a script main program which calls many functions, is to use the function stubs. A function stub

The IF Statement: The if statement selects whether or not the other statement, or group of statements, is executed. The common form of the if statement is as shown below: i

#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

Reading from Files: There are many lower level functions which read from files. The function fscanf reads the formatted data into a matrix, by using conversion formats like %s

Debugging Techniques: Any error in the computer program is called a bug. This word is thought to date back to the 1940s, whenever a problem with an early computer was found to

Vectors of nested structures: The Combining vectors and nested structures are possible to have a vector of structures in which several fields are structures themselves. Here i

Example of Vectorizing: Likewise, for an operation on a matrix, a nested loop would be needed; for illustration, supposing a matrix variable mat: [r c] = size(mat); for

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

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

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