MATLAB Answers

Static variables in MATLAB

187 views (last 30 days)
How do I declare static variable in MATLAB?

  0 Comments

Sign in to comment.

Accepted Answer

Abhishek Jain
Abhishek Jain on 6 Oct 2016
Edited: madhan ravi on 11 Nov 2018
Use keyword persistent to declare static variables
persistent x;

  0 Comments

Sign in to comment.

More Answers (1)

Adam
Adam on 6 Oct 2016
You can use persistent variables if that is what you mean, but only use them if you really need to. Similar to global variables they are far easier to introduce bugs into your workspace with then simply passing variables around between functions or using a class to define the scope of a variable.

  0 Comments

Sign in to comment.

Sign in to answer this question.