I'm trying to count the number of times the gui is being run on clicking a pushbutton. How to make the count continue even after the application is closed and started again. (i.e) if the count is 8 before closing ,it should start from 9 the next time

5 views (last 30 days)
I'm setting up the counter variables in the pushbutton callback and set the user data while the gui loads. \\before gui loads
\\PushButton CallBack
counter = get(hObject, 'UserData') + 1;
set(hObject, 'UserData', counter);
// As we are setting it to 0 , it is starting from 0 everytime. How to define a global varibale or something which can pass the previous count. //
Thanks for the help.

Accepted Answer

Jan Orwat
Jan Orwat on 5 Oct 2016
You may specify delete function which will be called each time application/gui is closed. Using this you may save all the variables you want to the file. Then using creation function you can bring those variables back. Read more about figure properties.
Jan Orwat
Jan Orwat on 6 Oct 2016
Edited: Jan Orwat on 6 Oct 2016
Write your own function, then specify it as a callback, for example DeleteFcn in gui figure. It will be called when one close the app. You can do it via button as well.

Sign in to comment.

More Answers (0)


Find more on Migrate GUIDE Apps 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!