Matlab is a technical computing program for engineers. Matlab includes a tool for building graphical user interfaces (GUIs) that lets users select objects from a palette of pre-coded elements and customise these objects using a property inspector. When it comes time for the user to test and use the GUI, it is important to program a method to close the GUI that ensures the user will not lose any work. This can be done by programming a close confirmation function.
- Skill level:
Other People Are Reading
Things you need
- Matlab R2007a or later version
Open Matlab and type "guide" in the command window.
Click the "Open Existing GUI" tab when prompted. Navigate to your saved GUI, select it, and click "OK."
Click the paper and pencil icon in the GUI editor window to open the m-file.
Add the following code under the first function listed on the m-file: "guidata(hObject, handles);"
Type the following code under the line of code you typed in step four: "set(handles.figure1,'CloseRequestFcn',@closeGUI);"
Type the following at the end of your m-file: "function closeGUI(src,evnt)"
Add this code under your new closeGUI function: "selection = questdlg('Do you want to close the GUI?','Close Request Function','Yes','No','Yes');"
Type "switch selection," on the next line of code.
Type "case 'Yes'," on the next line of code. Make sure this line is indented once.
Type "delete(gcf)" on the next line. Make sure this line is indented twice.
Type "case 'No'" on the next line. Make sure this line is indented once.
Type "return" on the next line. Make sure this line is indented twice.
Type "end" on the next line to finish your new close confirmation function. Save the m-file and you are finished.
Tips and warnings
- Make sure to put a semicolon where one was indicated in the steps above. Otherwise, errors will result.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for