File: persistent.mdc

package info (click to toggle)
freemat 4.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 141,800 kB
  • ctags: 14,082
  • sloc: ansic: 126,788; cpp: 62,046; python: 2,080; perl: 1,255; sh: 1,146; yacc: 1,019; lex: 239; makefile: 100
file content (49 lines) | stat: -rw-r--r-- 1,215 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

 Usage

Persistent variables are variables whose value persists
between calls to a function or script. The general syntax
for its use is

     persistent variable1 variable2 ... variableN

The persistent statement must occur before the variable is
the tagged as persistent. Per the MATLAB API documentation
an empty variable is created when the persistent statement
is called.


 Example

Here is an example of a function that counts how many times
it has been called.

       count_calls.m


  function count_calls
    persistent ccount
    if isempty(ccount); ccount = 0; end;
    ccount = ccount + 1;
    printf('Function has been called %d times\n',ccount);

We now call the function several times:

  --> for i=1:10; count_calls; end
  Function has been called 1 times
  Function has been called 2 times
  Function has been called 3 times
  Function has been called 4 times
  Function has been called 5 times
  Function has been called 6 times
  Function has been called 7 times
  Function has been called 8 times
  Function has been called 9 times
  Function has been called 10 times


* FreeMat_Documentation
* Variables_and_Arrays
* Generated on Thu Jul 25 2013 17:18:30 for FreeMat by
  doxygen_ 1.8.1.1