how to define a variable used one time in function
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
if i have a function with a variable x=1 defined in side that function and the variable is increased by a formula and that function is called many times from another function , the question is how can make that variable x defined in side the function is set only at the first call and after the other calls it will not effect or set to 1 again , or in another meaning how to define a variable used one time in function , please do not tell me to define x=1 out of function body because the program that i worked on not allowed .
for example :
Function ABC()
x=1;
x=x+Pi;
end
0 comentarios
Respuestas (2)
Mischa Kim
el 14 de Mzo. de 2014
Editada: Mischa Kim
el 14 de Mzo. de 2014
function xnew = ABC(x)
...
xnew = x + Pi;
end
to return the new value of x to the calling function.
1 comentario
Walter Roberson
el 14 de Mzo. de 2014
persistent x
if isempty(x); x = 1; else; x = x + 1; end
0 comentarios
Ver también
Categorías
Más información sobre Block Libraries en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!