SCRIPT Script Files

Section: Functions and Scripts

Usage

A script is a sequence of FreeMat commands contained in a .m file. When the script is called (via the name of the file), the effect is the same as if the commands inside the script file were issued one at a time from the keyboard. Unlike function files (which have the same extension, but have a function declaration), script files share the same environment as their callers. Hence, assignments, etc, made inside a script are visible to the caller (which is not the case for functions.

Example

Here is an example of a script that makes some simple assignments and printf statements.

     tscript.m
a = 13;
printf('a is %d\n',a);
b = a + 32

If we execute the script and then look at the defined variables

--> tscript
a is 13
b = 
  <int32>  - size: [1 1]
 45  
--> who
  Variable Name      Type   Flags             Size
              A      cell                    [1 3]
              B      cell                    [2 2]
              C      cell                    [1 2]
              D   complex                    [3 3]
              E  dcomplex                    [3 3]
              F    string                    [2 5]
              a     int32                    [1 1]
          accum     int32                    [1 1]
            ans    double                    [0 0]
           arg1     int32                    [1 1]
           arg2     int32                    [1 1]
              b     int32                    [1 1]
             c1    string                    [1 12]
             c2    string                    [1 12]
             c3    string                    [1 14]
             fp    uint32                    [1 1]
              i     int32                    [1 1]
              k     int32                    [1 1]
              y     int32                    []

we see that a and b are defined appropriately.