MATLAB: How to lock the current directory while a GUI-based program is running

current directorygui

Hello, I've got a large GUI-based program that I'd like to error-proof by ensuring that the user doesn't change the current directory.
E.g., if she changes the directory, and then tries to close the program, an error comes up because MATLAB can no longer find the CloseRequestFcn. 🙁 Same goes for countless other cases.
Any idea how this might be done? (My backup plan is to just make the main GUI window modal, preventing any other MATLAB window from being selected.)

Best Answer

Modal dialogs are not user-friendly, therefore I recommend to avoid this feature whenever it is possible.
Arthur's suggestion to add the folder to the Matlab path is the standard solution for finding functions in a specific folder.
further methods are nested functions and the creation of function handles to all subfunctions during the creation of the GUI. These function handles are independent from the current folder.