5

I am creating a GUI in matlab using guide. It's non-blocking (not calling uiwait). When the gui window is closed, I would like to execute some clean up code.

Is there an gui_ClosingFcn callback I should define in analogy to the gui_OpeningFcn template that guide creates for me?

Marc
  • 5,315
  • 5
  • 30
  • 36

2 Answers2

14

Figure windows have a 'DeleteFcn' property, which defines a callback function that will run when the window is closed/deleted. You could potentially use that to do your clean-up.

gnovice
  • 125,304
  • 15
  • 256
  • 359
  • 3
    set(hObject, 'DeleteFcn', @myhandle) in the openingFcn should do the trick then. Thanks. – Marc Jun 08 '10 at 19:39
12

Figure windows have a CloseRequestFcn property, which defines a callback function that will run when the window is closed (before deleting the window). enter image description here

Dariush Jafari
  • 5,223
  • 7
  • 42
  • 71
  • +1 Branching at the close request level is cleaner IMHO as it enables to reuse a `close` function of the enclosing object. That way, the figure can be closed either programmatically or via the GUI through the same function. – P-Gn Aug 20 '15 at 13:45