clear a MATLAB function after an episode

조회 수: 1 (최근 30일)
Abdul Basith Ashraf
Abdul Basith Ashraf 2021년 4월 8일
편집: Julius Muschaweck 2021년 4월 8일
There is a persistent variable in a function and I need to clear it before every episode of deep RL training. How do I achieve this?
The path of the function is
[mdl "/Check if Done/MATLAB Function"]
Thanks

답변 (1개)

Julius Muschaweck
Julius Muschaweck 2021년 4월 8일
편집: Julius Muschaweck 2021년 4월 8일
Assuming your function has the name f, you can use clear f; to clear persistent variables within f.
Like here:
function f()
persistent p
if isempty(p)
p = 42;
fprintf('p was empty, now p == %g\n',p)
else
p = p+1;
fprintf('p == %g\n',p);
end
end
If you then execute
f();
f();
f();
clear f;
f();
f();
you will get
p was empty, now p == 42
p == 43
p == 44
p was empty, now p == 42
p == 43

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by