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 CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by