Rename a variable within global (function in function)
조회 수: 2(최근 30일)
표시 이전 댓글
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?
댓글 수: 0
채택된 답변
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
추가 답변(0개)
참고 항목
범주
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!