Defining persistent variables in a function

1 回表示 (過去 30 日間)
Deepa Maheshvare
Deepa Maheshvare 2020 年 5 月 5 日
回答済み: Rik 2020 年 5 月 5 日
I've a function that is called multiple times
function fun()
persistent x y z
if isempty(x)
x = %
end
if isempty(y)
y = %
end
if isempty(z)
z = %
end
end
How can I do better without having multiple if statements? Can we vectorize the variables and check once?
Any suggestions will be really helpful

採用された回答

Rik
Rik 2020 年 5 月 5 日
You can use use this:
function fun()
persistent x y z
if isempty(x)
x = %
y = %
z = %
end
%rest of your function
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by