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
Example of Nested functions: For illustration, the function below computes and returns the volume of a cube. Three arguments are then passed to it, for the width and length of

Working of Editor and debugger: Editor/Debugger, or commands can be typed from Command Window. For illustration, the dbstop command below will set a breakpoint in the fifth li

Run-time or execution-time error: The Run-time, or execution-time, errors are found whenever a script or function is executing. With most of the languages, an illustration of

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

Example of Functions which complete a task: For illustration, the function below just prints the number arguments passed to it in a sentence format: As this function i

Illustration of Input in a for loop: In this illustration, the loop variable iv iterates through the values 1 through 3, therefore the action is repeated three times. The acti

WHILE Loops: The while statement is used as a conditional loop in MATLAB; it is used to repeat an action whenever ahead of the time it is not known how many times the action w

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

Rectangle - graphics objects: The other core graphics object is the rectangle that can have curvature added to it (!!). Merely calling the function rectangle without any argum

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