Static or persistent variables over several functions in the same file in Matlab Coder
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
A C source file can have static variables declared outside the functions in a source code file, accessible for all functions in the same file. Is it possible to achieve the same result in Matlab Coder, using e.g. the persistent function? An example: I have a single m-file with an entry-point function and subfunctions:
function entry_point_fcn()
persistent static_var;
if isempty(static_var)
static_var = 1;
end
sub_fcn1();
sub_fcn2();
end
function sub_fcn1()
static_var = static_var + 1;
end
function sub_fcn2()
static_Var = static_Var * 2;
end
With all 3 functions in the same file I want static_var to be shared over all 3 functions without using it as input to sub_fcn1 or sub_fcn2, and without using global variables. This should result in a C file with static_var being a static variable outside the three functions.
I know this example has easy workarounds, but I want to be able to make static variables in generated C files.
0 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre MATLAB Coder 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!