| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
close
close(h)
close name
close all
close all hidden
close all force
status = close(...)
close deletes the current figure or the specified figure(s). It optionally returns the status of the close operation.
close deletes the current figure (equivalent to close(gcf)).
close(h) deletes the figure identified by h. If h is a vector or matrix, close deletes all figures identified by h.
close name deletes the figure with the specified name.
close all deletes all figures whose handles are not hidden.
close all hidden deletes all figures including those with hidden handles.
close all force deletes all figures, including GUIs for which CloseRequestFcn has been altered to not close the window.
status = close(...) returns 1 if the specified windows have been deleted and 0 otherwise.
The close function works by evaluating the specified figure's CloseRequestFcn property with the statement
eval(get(h,'CloseRequestFcn'))
The default CloseRequestFcn, closereq, deletes the current figure using delete(get(0,'CurrentFigure')). If you specify multiple figure handles, close executes each figure's CloseRequestFcn in turn. If an error that terminates the execution of a CloseRequestFcn occurs, the figure is not deleted. Note that using your computer's window manager (i.e., the Close menu item) also calls the figure's CloseRequestFcn.
If a figure's handle is hidden (i.e., the figure's HandleVisibility property is set to callback or off and the root ShowHiddenHandles property is set to on), you must specify the hidden option when trying to access a figure using the all option.
To delete all figures unconditionally, use the statements
set(0,'ShowHiddenHandles','on') delete(get(0,'Children'))
The figure CloseRequestFcn allows you to either delay or abort the closing of a figure once the close function has been issued. For example, you can display a dialog box to see if the user really wants to delete the figure or save and clean up before closing.
When coding a CloseRequestFcn callback, make sure that it does not call close, because this sets up a recursion that results in a MATLAB warning. Instead, the callback should destroy the figure with delete. The delete function does not execute the figure's CloseRequestFcn; it simply deletes the specified figure.
delete | figure | Figure: HandleVisibility | gcf | Root: ShowHiddenHandles
![]() | clock | close (Tiff) | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |