Defining persistent variables in a function
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!