Rename a variable within global (function in function)
5 visualizaciones (últimos 30 días)
new2matlab el 3 de Feb. de 2020
I am creating a new function that includes a previously created function in the hopes of editing the inputs. However, I am wanting to edit two variables that are stored within the Global set. Is there a way to do this and pass by the global to set a new input value for all the functions that are called within?
Spencer Chen el 3 de Feb. de 2020
Simply assign it to another variable.
saved_evil_global_val = evil_global_var;
evil_global_var = new_val;
... % do your stuff here
evil_global_var = saved_evil_global_val; % retore your global value here
Now, most globals are unncessary and can be replaced be well-defined functions with input arguments.