How do I use persistent variables in MATLAB Function Blocks?
Show older comments
I have a MATLAB function block that uses a persistent variable 'n' to calculate the output.
In my MATLAB function block I initialize persistent variable 'n' as 1 when the input to the MATLAB function block is 0, but I still get an error saying:
Persistent variable 'n' is undefined on some execution paths.
My MATLAB function block takes a counter as input, hence, the input is always 0 at the first time step which leads to initialization of 'n'.
Why am I getting this error and how do I get around it?
Please find a simple model which reproduces this issue.
Accepted Answer
More Answers (0)
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!