Defining persistent variables in a function

1 Ansicht (letzte 30 Tage)
Deepa Maheshvare
Deepa Maheshvare am 5 Mai 2020
Beantwortet: Rik am 5 Mai 2020
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

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Historical Contests finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by