File: exist.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 (97 lines) | stat: -rw-r--r-- 2,184 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

 Usage

Tests for the existence of a variable, function, directory
or file. The general syntax for its use is

    y = exist(item,kind)

where item is a string containing the name of the item to
look for, and kind is a string indicating the type of the
search. The kind must be one of

* 'builtin' checks for built-in functions
* 'dir' checks for directories
* 'file' checks for files
* 'var' checks for variables
* 'all' checks all possibilities (same as leaving out kind)

You can also leave the kind specification out, in which case
the calling syntax is

    y = exist(item)

The return code is one of the following:

* 0 - if item does not exist
* 1 - if item is a variable in the workspace
* 2 - if item is an M file on the search path, a full
  pathname to a file, or an ordinary file on your search
  path
* 5 - if item is a built-in FreeMat function
* 7 - if item is a directory

Note: previous to version 1.10, exist used a different
notion of existence for variables: a variable was said to
exist if it was defined and non-empty. This test is now
performed by isset.


 Example

Some examples of the exist function. Note that generally
exist is used in functions to test for keywords. For
example,

    function y = testfunc(a, b, c)
    if (~exist('c'))
      % c was not defined, so establish a default
      c = 13;
    end
    y = a + b + c;

An example of exist in action.

  --> a = randn(3,5,2)

  a =

  (:,:,1) =
      0.7785    0.6357    1.7582    1.5784   -0.8470
      0.7235    1.0468   -0.6919   -0.6796    0.4767
      0.2100    0.0865    1.5704   -0.1267    2.1381

  (:,:,2) =
      1.5525   -0.2908   -1.4220    1.1076    0.2419
      0.1652   -0.5668   -0.8018   -0.5975    0.8483
      0.3147   -0.1109   -0.5203    0.5851    1.1503

  --> b = []

  b =
    []
  --> who
    Variable Name       Type   Flags             Size
                a    double                    [3x5x2]
                b    double                    [0x0]
  --> exist('a')

  ans =
   1

  --> exist('b')

  ans =
   1

  --> exist('c')

  ans =
   0


* FreeMat_Documentation
* Inspection_Functions
* Generated on Thu Jul 25 2013 17:17:38 for FreeMat by
  doxygen_ 1.8.1.1