MATLAB: How to define a variable that store its value after closing MATLAB file

globalpersistentstatic

Hi,
I just want to declare a variable that holds its value through the whole file and even after closing it , also to initialize it externally . I tried to use 'persistent' variables but they're locally defined and so I have to initialize it locally , that makes its value initialized each time the function is called. When I define it global to avoid the repeated initialization through the same file , a warning appears 'the variable can apparently be used before it's defined' and an error 'undefined variable'. I need this variable to save txt files that contains the incremented variable value in its name.
Thanks in advance

Best Answer

Thank you very much Jan Simon for your answer and thank u all
but I found a solution for my question , and it works as I want .. I just used a text file to keep the variables that I want them not to lose their values and I used them in my program (using save and load commands) only to be incremented to use them in naming a series of files . I don't know if I explained that well but I just want to close this question .