Clear persisent variable in for loop

조회 수: 1 (최근 30일)
Deepa Maheshvare
Deepa Maheshvare 2020년 3월 5일
댓글: Rik 2020년 3월 5일
I've the following code
function fun(i)
persistent ss
persistent s
s = vercat(s,rand(1,2))
if i== 4
ss(j) = s ;
% here I want to clear the persistent variable s
end
end
The above function is executed in the following manner
for j = 1:4
for i = 1:4
i
fun(i)
end
end
I would like to ask for suggestions on how to clear the persistent variable s when i = 4.
  댓글 수: 1
Rik
Rik 2020년 3월 5일
Why do you want to do this?

댓글을 달려면 로그인하십시오.

답변 (1개)

Robert U
Robert U 2020년 3월 5일
Hello Deepa Maheshvare,
According to documentation persistent variables can be cleared by clearing the function from memory. If you want to reset the value of the variable within the function just assign a new value (which could be [] as well).
Kind regards,
Robert

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by