matlab - How to use a parameter as a global variable in a .m file? -


to describe mean, give example here:

function y = f(x,a) global y = f1(x);  function y = f1(x) global y = x + a; 

here, want variable 'a' used global variable can called subfunction 'f1' compute $x+a$. (my purpose reduce transformation of parameters)

but function not work, unless define new variable 'b' restore value of 'a'.

the question is, how can make 'a' global variable directly, without defining new variable?

i not recommend use global variables, since pass function f.

the behavior want can obtained without global variables, using nested functions:

function y = f(x,a) y = f1(x);    function y = f1(x)    y = x + a;    end end 

Comments

Popular posts from this blog

Cursor error with postgresql, pgpool and php -

delphi - ESC/P programming! -

c++ - error: use of deleted function -