Rename a variable within global (function in function)

1 回表示 (過去 30 日間)
new2matlab
new2matlab 2020 年 2 月 3 日
回答済み: Spencer Chen 2020 年 2 月 3 日
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
Spencer Chen 2020 年 2 月 3 日
Simply assign it to another variable.
global evil_global_var;
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.
Blessings,
Spencer

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by