onCleanup
Last updated
Last updated
a = onCleanup(@() disp('Cleanup executed'))
clear afunction cleanupExample(doCancel)
disp('Display Figure')
f = figure;
cleanup = onCleanup(@()atTheEnd(f));
if doCancel
cleanup.cancel(); % other syntax: cancel(cleanup);
end
sleep(5)
end
function atTheEnd(f)
disp('Close Figure')
close(f)
end
cleanupExample(false);
cleanupExample(true);