필터 지우기
필터 지우기

Do I have to redefine my cleanup object when input arguments change?

조회 수: 1 (최근 30일)
Dan Klisiewicz
Dan Klisiewicz 2021년 4월 20일
I have a cleanup function that relies on a couple of arguments that alter the behavior of the cleanup routine:
function MainFunction()
x=1;
y=1;
cleanupObj = onCleanup(@()cleanupFun(x,y));
end
function cleanupFun(x,y)
if(x)
%do something
end
if(y)
%do another thing
end
end
Now, in my broader use case, x and y will be changing many times throughout the life of MainFunction. Do I have to redefine my cleanupObj everytime x or y changes? For my case this would be quite ugly.
Another idea I've thought of is making use of the fact that x and y are changed by subfunctions. Is it possible to pass the cleanup object handle to these subfunctions so that I can redefine the cleanup object handle from within the subfunction, rather than redefining it after each call to the sub function?

답변 (0개)

카테고리

Help CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by