Global Command

hi i usually use Matlab and i wolud like to know if there is in GAUSS a command like "global" in Matlab

 the command global in matlab works in the next way

  if you declare a variable as global in matlab, it will be stored  in another workspace "Global workspace",  in order to be called at any moment, even though it's not in the current workspace

1 Answer



0



Inside of GAUSS procedures, you can reference local variables or global variables. For example:

//Create global variable
x = 5;

//Call to 'foo' will return 10
foo(2, 3);


proc (1) = foo(a, b);
    local out;
    
    //out, a and b are 'local' to 'foo'
    //'x' is a global variable
    out = a + b + x;
    retp(out);
endp;

However, to protect you from just forgetting to make a variable inside of a GAUSS procedure a local variable, GAUSS requires that the global variable referenced inside of the procedure exist before the procedure is defined. For example:

//Clear out all global variables
new;

proc (1) = foo(a, b);
    local out;
    
    //out, a and b are 'local' to 'foo'
    //'x' is a global variable
    out = a + b + x;
    retp(out);
endp;

Will return an error that x is undefined. You can tell GAUSS that there will be a global x by using the declare statement, like this:

//Tell GAUSS there will be a global 'x'
declare x;

//Clear out all global variables
new;

proc (1) = foo(a, b);
    local out;
    
    //out, a and b are 'local' to 'foo'
    //'x' is a global variable
    out = a + b + x;
    retp(out);
endp;

aptech

1,773

Your Answer

1 Answer

0

Inside of GAUSS procedures, you can reference local variables or global variables. For example:

//Create global variable
x = 5;

//Call to 'foo' will return 10
foo(2, 3);


proc (1) = foo(a, b);
    local out;
    
    //out, a and b are 'local' to 'foo'
    //'x' is a global variable
    out = a + b + x;
    retp(out);
endp;

However, to protect you from just forgetting to make a variable inside of a GAUSS procedure a local variable, GAUSS requires that the global variable referenced inside of the procedure exist before the procedure is defined. For example:

//Clear out all global variables
new;

proc (1) = foo(a, b);
    local out;
    
    //out, a and b are 'local' to 'foo'
    //'x' is a global variable
    out = a + b + x;
    retp(out);
endp;

Will return an error that x is undefined. You can tell GAUSS that there will be a global x by using the declare statement, like this:

//Tell GAUSS there will be a global 'x'
declare x;

//Clear out all global variables
new;

proc (1) = foo(a, b);
    local out;
    
    //out, a and b are 'local' to 'foo'
    //'x' is a global variable
    out = a + b + x;
    retp(out);
endp;

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy